Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Having troubles connecting dbus signal to qt slot
Qt 6.11 is out! See what's new in the release blog

[Solved] Having troubles connecting dbus signal to qt slot

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LinGreg
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LinGreg
        wrote on last edited by
        #3

        THANKS! I knew I was missing a rather simple, yet very important (and fundamental), piece of information. Thanks for humoring my ignorance!

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          You're Welcome :) You can mark the post as solved by editing the post title and prepending [Solved].

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved