Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

Gtk Hello World in Qt C++

Posted on May 24, 2013

Recently I’ve been working on the smoke-gobject bindings in the evenings and weekends. Although I’m working on other things for my job at Codethink during the day, I’m sufficiently excited about these bindings to be unable to stop spending my free time on them. This is at the expense of working on the new version 3.0 of QtRuby sadly. I’ll try to explain on this blog why I think the Smoke/GObject bindings will be important for the parties attending the forthcoming Desktop Summit to consider, and why I’m giving them a higher priority than Ruby.

As the title of the blog suggests I’ve just got a Gtk Hello World working, written in Qt. Here is the code:
[sourcecode language=”cpp”]
#include <QtCore/QObject> #include <gdk.h> class MyObject : public QObject { Q_OBJECT public: MyObject(QObject *parent = 0); public slots: void hello(); bool deleteEvent(Gdk::Event e); void destroy(); }; … #include <QtCore/qdebug.h> #include <gtk.h> #include "myobject.h" MyObject::MyObject(QObject *parent) : QObject(parent) { } void MyObject::hello() { qDebug() << "Hello World"; } bool MyObject::deleteEvent(Gdk::Event e) { qDebug() << "delete event occurred"; return true; } void MyObject::destroy() { Gtk::mainQuit(); } … #include <gtk.h> #include <gtk_window.h> #include <gtk_button.h> #include <QtCore/qobject.h> #include "myobject.h" int main(int argc, char *argv[]) { Gtk::init(argc, argv); MyObject obj; Gtk::Window *window = new Gtk::Window(Gtk::WindowTypeToplevel); window->setBorderWidth(10); QObject::connect(window, SIGNAL(deleteEvent(Gdk::Event)), &obj, SLOT(deleteEvent(Gdk::Event))); QObject::connect(window, SIGNAL(destroy()), &obj, SLOT(destroy())); Gtk::Button *button = Gtk::Button::createWithLabel("Hello World"); QObject::connect(button, SIGNAL(clicked()), &obj, SLOT(hello())); QObject::connect(button, SIGNAL(clicked()), window, SLOT(destroy())); window->slotAdd(button); button->slotShow(); window->slotShow(); Gtk::main(); return 0; }
[/sourcecode]
You can compare the Gtk C equivalent example code in this Getting Started Gtk tutorial. I could spend lots of space explaining what it is all about, but anyone familiar with Qt programming ought to be able to understand the code without any explanation – that is the clever thing in fact!

This demonstrates that an auto-generated binding for GObject libraries described by GObject Introspection .gir files can seamlessly inter-operate with Qt libraries. And it looks much the same as a native Qt library to a Qt programmer.

Normally a language binding for Gtk that allows you to write an app to show a hello world button is a fine thing. But those normal language bindings don’t mean that you have united two of the major Linux desktop communities, they just mean that you can write Gtk programs in the language of your choice. So to me, this latest binding is different in kind; it is an opportunity to integrate both libraries and communities, and it isn’t limited to being able to program Gtk in your latest nifty language.

I’m going to the GObject Introspection Hackfest in Berlin, which should allow us to nail down the technical details and get close to bringing the Smoke Gobject bindings up to production quality. It will also be about the social side of linking the two communities in conjunction with the technical discussions.

The Smoke GObject apis are described with QMetaObjects, and that means that the apis will ‘just work’ with QML. I am looking forward to trying out Clutter programming in QML soon, as I believe that should be possible. That shows that these bindings are not just about C++ programming, but languages like QML and QtScript that are driven by QMetaObject introspection too.

You can get the latest version of the gobject-smoke bindings from the Smoke GObject Launchpad project. See the README file for an explanation of what to do with them.

via Richard Dale @KDE Blog

Terbaru

  • Belum Tahu? Gini Caranya Dapat Bisnis Sukses Cuma dari Clipping Video Pake AI
  • Inilah Rahasia Perbaiki Algoritma Video YouTube yang Mulai Sepi
  • Kenapa Cicilan di Bank Syariah Itu Tetap?
  • Inilah 7 Produk Digital Paling Realistis untuk Kalian yang Mau Jualan Online Tahun Ini!
  • Inilah 4 Strategi Memilih Niche SEO Terbaik Supaya Blog Kalian Cepat Ranking
  • Ini Trik Supaya Pengunjung Toko Online Kalian Jadi Pembeli Setia Pakai Omnisend!
  • 3 Strategi AI Terbukti Biar Bisnis E-Commerce Kalian Makin Cuan 2026!
  • Inilah 6 Langkah Tembus 5.000 Follower di X, Gini Caranya Supaya Akun Kalian Nggak Stuck Lagi!
  • SEO LinkedIn: Inilah Alasan Kenapa LinkedIn Ads Lebih Efektif Buat Bisnis B2B Dibanding Platform Lain
  • Inilah Alasan Kenapa Kolom Komentar YouTube Kalian Sering Menghilang Secara Misterius!
  • Cara Kelola Auto-Posting Semua Media Sosial Kalian Pakai Metricool
  • Studi Kasus Sukses Instagram Maria Wendt Dapat 12 Juta View Instagram Per Bulan
  • ZenBook S16, Vivobook Pro 15 OLED, ProArt PX13, dan ROG Zephyrus G14, Laptop Bagus dengan Layar OLED!
  • Caranya Ngebangun Website Directory dengan Traffic Tinggi dalam Seminggu!
  • Cara Mengembangkan Channel YouTube Shorts Tanpa Wajah
  • Inilah Cara Menghitung Diskon Baju Lebaran Biar Nggak Bingung Saat Belanja di Mall!
  • Cara Jitu Ngebangun Bisnis SaaS di Era AI Pakai Strategi Agentic Workflow
  • Inilah Rincian Gaji Polri Lulusan Baru 2026, Cek Perbedaan Jalur Akpol, Bintara, dan Tamtama Sebelum Daftar!
  • Inilah 5 Channel YouTube Membosankan yang Diam-diam Menghasilkan Banyak Uang
  • Inilah Cara Pakai Google Maps Offline Biar Mudik Lebaran 2026 Nggak Nyasar Meski Tanpa Sinyal!
  • Inilah Alasan Mahkamah Agung Tolak Kasasi Google, Denda Rp202,5 Miliar Resmi Menanti Akibat Praktik Monopoli
  • Inilah Cara Daftar dan Syarat SPMB SMK Boarding Jawa Tengah 2026, Sekolah Gratis Sampai Lulus!
  • Inilah Daftar Sekolah Kedinasan 2026 untuk Lulusan SMK, Bisa Kuliah Gratis dan Berpeluang Besar Langsung Jadi CPNS!
  • Inilah Pajak TER: Skema Baru PPh 21 yang Nggak Bikin Pusing, Begini Cara Hitungnya!
  • Inilah Jadwal Resmi Jam Buka Tol Jogja-Solo Segmen Prambanan-Purwomartani Saat Mudik Lebaran 2026
  • Inilah Cara Mendapatkan Witherbloom di Fisch Roblox, Rahasia Menangkap Ikan Paling Sulit di Toxic Grove!
  • Kenapa Indomart Point Bisa Kalahkan Bisnis Kafe?
  • Inilah Cara Mendapatkan Rotten Seed di Fisch Roblox, Lokasi Rahasia di Toxic Grove Buat Unlock Toxic Lotus!
  • Inilah Cara Zakat Crypto Kalian Bisa Jadi Pengurang Pajak Berdasarkan Aturan Resmi Pemerintah!
  • Inilah Perbandingan Airwallex vs Payoneer 2026: Jangan Sampai Profit Kalian Ludes Gara-Gara Biaya Admin!
  • How to Fix Taskbar Icon Order in Windows 11/10
  • How to Disable Personalized Ads in Copilot on Windows 11
  • What is the Microsoft Teams Error “We Couldn’t Connect the Call” Error?
  • Why Does the VirtualBox System Service Terminate Unexpectedly? Here is the Full Definition
  • Why is Your Laptop Touchpad Overheating? Here are the Causes and Fixes
  • How to Use Orbax Checkpointing with Keras and JAX for Robust Training
  • How to Automate Any PDF Form Using the Power of Manus AI
  • How to Training Your Own YOLO26 Object Detection Model!
  • How to Build a Full-Stack Mobile App in Minutes with YouWare AI
  • How to Create Consistent Characters and Cinematic AI Video Production with Seedance
  • Apa itu Spear-Phishing via npm? Ini Pengertian dan Cara Kerjanya yang Makin Licin
  • Apa Itu Predator Spyware? Ini Pengertian dan Kontroversi Penghapusan Sanksinya
  • Mengenal Apa itu TONESHELL: Backdoor Berbahaya dari Kelompok Mustang Panda
  • Siapa itu Kelompok Hacker Silver Fox?
  • Apa itu CVE-2025-52691 SmarterMail? Celah Keamanan Paling Berbahaya Tahun 2025

©2026 emka.web.id | Design: Newspaperly WordPress Theme