[Solved] Having troubles connecting dbus signal to qt slot
-
I'm not sure where I should post this -- my appologies it I'm in the wrong place. I'm having loads of troubles trying to connect a dbus signal to a qt slot. Basically I want to connect a qt slot the a KDE dbus signal (this is on a linux system running KDE). I included code to try to exemplify my problem.
In the code below, I'm trying to connect "wakeup" of "my_obj" to the dBus signal "profileChanged". But, even though I'm sure (via qbusviewer) that this signal is being emitted, "wakeup" will not run. Here is my header:
@
class my_wake_up_class : public QObject
{
Q_OBJECT
public slots:
void wakeup(QString); //Does not run!
};
@and my main code:
@
#include "test.h"const QString service = "org.kde.Solid.PowerManagement";
const QString path = "/org/kde/Solid/PowerManagement";
const QString interface = "org.kde.Solid.PowerManagement";void my_wake_up_class::wakeup(QString a)
{
std::cout << "this should run" << std::endl;
}int main()
{
QDBusConnection bus = QDBusConnection::sessionBus();if (!bus.isConnected()) { qDebug() << "Can't connect to the D-Bus session bus.\n"; } my_wake_up_class my_obj; bool conn = bus.connect(service, path, interface, "profileChanged", &my_obj, SLOT(wakeup(QString))); if (!conn) qDebug() << "not connected"; for(;;) { usleep(100000); } return 0;
}
@So when "profileChanged" is emited (which I'm sure it is from qdbusviewer) the "wakeup" is not being called (as it should) and I not getting any error nor warnings. I'm sure that "profileChanged"'s sigature is of the form "void (QString)" from the qdbus output, which is:
bq. signal void org.kde.Solid.PowerManagement.profileChanged(QString)
I've no clue what I've done wrong (I haven't found anything in the documentation that is remotedly helpful). Does anyone know how to do this? Thanks.
-
Hi,
To make this work you will need to enable Qt Event system. The best way would be to wrap your code inside QApplication.
eg:
@
QApplication a(argc, argv);
QDBusConnection bus = QDBusConnection::sessionBus();if (!bus.isConnected()) {
...return a.exec();
@Also adding sleep functions would block that system and the events would never be delivered.
-
THANKS! I knew I was missing a rather simple, yet very important (and fundamental), piece of information. Thanks for humoring my ignorance!
-
You're Welcome :) You can mark the post as solved by editing the post title and prepending [Solved].