View Single Post
Posts: 107 | Thanked: 74 times | Joined on Jan 2010
#99
Just for those that thinks qt is not easy, this is little tool that shows how to create a button that when clicked emit a signal on the session bus.

mywidget.h
Code:
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QDBusConnection>

class MyWidget : public QWidget
{
  Q_OBJECT
  public:
  MyWidget() : QWidget() {
    QDBusConnection::sessionBus().registerObject("/",this,QDBusConnection::ExportAllContents);
    new QVBoxLayout(this);
    QPushButton *b = new QPushButton("emit signal",this);
    layout()->addWidget(b);
    connect(b,SIGNAL(clicked()),SIGNAL(clicked()));
    show();
  }
  signals:
    void clicked();
};
main.cpp
Code:
#include <QApplication>
#include "mywidget.h"

int main(int argc, char **argv)
{
  QApplication app(argc, argv);
  new MyWidget();
  return app.exec();
}
gui_dbus.pro
Code:
SOURCES += main.cpp
QT += gui dbus
HEADERS += mywidget.h
That's was done in 2 minutes using vi, 20 seconds of that was spent to launch "assistant", type in the search bar "registerObject", click on RegisterOptions and retrieve QDBusConnection::ExportAllContents define that I always do not remember.

Further some seconds to build and launch:

qmake; make; ./gui_dbus

tested with dbus-monitor:

signal sender=:1.223 -> dest=(null destination) serial=6 path=/; interface=local.MyWidget; member=clicked

Now convince me that is easy and fast to use gtk, dbus lib, autoscan, autoreconf, configure, pkgconfig, and so on....
 

The Following User Says Thank You to nicola.mfb For This Useful Post: