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

  • Apa Itu Pengertian Penonaktifan SPayLater? Ini Durasi Blokir Akibat Telat Bayar
  • Apa Itu Rasio Gambar Ukuran 1:1 di Canva? Ini Pengertian dan Cara Buatnya
  • Pengiriman Shopee Express Hemat itu Berapa Lama? Ini Pengertian dan Estimasi Sampainya
  • Android 2025: Aplikasi Baru dan Smartphone Impian yang Akan Datang!
  • Apa Itu Google AI Pro Ultra? Ini Pengertian dan Penjelasan Lengkapnya
  • Apa Itu Error Gagal Kirim Nilai RDM 3.1? Ini Pengertian dan Solusi Mengatasinya
  • Facebook Mulai Batasi Link Eksternal Cuma 2 Sebulan! Ini Trik Mengatasinya
  • Cara Nonton Tensura Season 4! Bakal Tayang April 2026 dengan Format 5 Cour
  • Belum Tahu? Inilah Trik Supaya Live TikTok Kalian Aman dan Banjir Cuan
  • Pixel 8 Dapatkan Mode Panorama Baru! Hasil Foto Lebih Luas & Lebih Kreatif
  • Apa Itu AppLocker? Ini Pengertian dan Cara Mengamankan Windows 11 Kalian dari Skrip Jahat
  • Cara Membuat Riwayat Copilot Kamu Tetap Bersih dan Rapi!
  • Game & Aplikasi Android Terbaik Saat Diskon Liburan Natal! Jangan Ketinggalan!
  • Apa Itu Game Prison Escape Journey? Ini Pengertian dan Cara Mainnya untuk Pemula
  • “Listrik Gratis” dari Solar Panel Cuma Mitos?! Ini Sisi Gelap PLTS
  • Samsung Galaxy Z-Fold: Uji Jatuh Bebas yang Mengguncang Keandalan Lipatannya
  • Google One 2026: Apa yang Akan Jadi Fitur Utama dan Harga yang Diharapkan?
  • Apa Itu Error 0x800704f8? Ini Pengertian dan Cara Mengatasinya
  • Android Akhirnya Dapat GPS Darurat di India! Setelah Hampir 10 Tahun
  • Apa Itu GetContact Premium? Ini Pengertian dan Cara Daftarnya
  • Android Maze Figure: Koleksi Baru Google yang Bikin Penggemar Bergairah!
  • Google Update Besar-besaran Desember 2025: Apa yang Akan Memengaruhi Pengalaman Anda?
  • Masih Pusing Hitung Gaji Manual? Waktunya Pakai Aplikasi HR
  • Apa Itu Dustruco? Ini Pengertian dan Cara Pasangnya di HP Kalian
  • Apa Itu Aplikasi Dooie Live? Ini Pengertian dan Cara Pakai Aplikasinya untuk Cari Jodoh
  • Apa Itu Battle Emote Jefri Nichol dan Om Telolet Om di MLBB? Ini Penjelasannya
  • Apa itu Game Luna Mobile dan Bagaimana Cara Menangnya?
  • Apa Itu Kompensasi Sistem Trail Mobile Legends? Ini Penjelasan dan Cara Klaim Hadiahnya
  • Apa Itu Update Google Pixel 2 Desember 2025? Ini Penjelasannya!
  • Ini Cara Reset Desil di Aplikasi Cek Bansos Biar Valid (Update Januari 2026)
  • Apa itu Cosmic Desktop: Pengertian dan Cara Pasangnya di Ubuntu 26.04?
  • Apa Itu Auvidea X242? Pengertian Carrier Board Jetson T5000 dengan Dual 10Gbe
  • Elementary OS 8.1 Resmi Rilis: Kini Pakai Wayland Secara Standar!
  • Apa Itu Raspberry Pi Imager? Pengertian dan Pembaruan Versi 2.0.3 yang Wajib Kalian Tahu
  • Performa Maksimal! Ini Cara Manual Update Ubuntu ke Linux Kernel 6.18 LTS
  • Inilah Cara Kuasai Materi Sulit dalam Hitungan Menit Pakai Google NotebookLM: Tutorial Lengkap
  • Inilah Cara Membuat AI Agent Cerdas dan Memantaunya Menggunakan LangGraph dan LangSmith
  • Ini Alasan China Akan Menang di Dunia AI
  • Apa Itu AI Gateway? Ini Definisi Tulang Punggung Infrastruktur AI Modern
  • Apa Itu Google AI Pro Ultra? Pengertian dan Bedah Fitur Terbarunya
  • Apa Itu Serangan Phishing OAuth di Microsoft 365? Ini Definisi dan Cara Kerjanya
  • Apa Itu Distribusi Malware Via YouTube? Ini Pengertian dan Bahayanya Buat Kalian
  • Apa Itu Undang-Undang NDAA? Ini Pengertian dan Dampaknya Bagi Cyber Command Amerika Serikat
  • Tagihan AWS Sekarang Bisa Dibayar Pakai BNB via BPN, Ini Caranya!
  • Video Botol Teh Pucuk 1 Menit 50 Detik yang Viral di TikTok! Hati-Hati Kejahatan Siber
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV

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