Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Receiving system D-Bus events (signals) and responding to them

    General and Desktop
    1
    2
    89
    Loading More Posts
    • 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.
    • swirl
      swirl last edited by

      Title. I specifically need to respond to org.freedesktop.login1.Manager.PrepareForSleep, by closing out the application and deallocating all memory in order to prevent memory dumps and the such. However, after scouring the docs for a few hours--I've got nothing. I can't seem to find a way to respond to system events--Qt only provides an example for sending and receiving stuff at a custom destination.

      Here's a snippet of code I tried:

      class Test : public QDBusAbstractAdaptor
      {
          Q_OBJECT
          Q_CLASSINFO("D-Bus Interface", "org.freedesktop.login1.Manager")
      public:
          Test(QObject *obj) : QDBusAbstractAdaptor(obj)
          { }
      signals:
          void PrepareForSleep();
      };
      

      And in the main function:

      QObject obj;
      Test *test = new Test(&obj);
      QObject::connect(pong, &Test::PrepareForSleep, test, [] {
          qDebug() << "Preparing for sleep";
      });
      
      QDBusConnection::sessionBus().registerObject("/", &obj);
      

      However, when this event occurs (like when I suspend my computer), nothing shows up and the app just continues.

      Like I said I can't make anything of the docs. Maybe I'm doing something wrong, but I tried a bunch of different things and it just didn't work. I know it's possible because QDBusViewer can connect to signals and show their info, but I once again can't figure out how it does it.

      the

      1 Reply Last reply Reply Quote 0
      • swirl
        swirl last edited by

        I've found I can do something like

        QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep")
        

        however, I don't know what I'm supposed to do with this. It says I need to provide a slot with the correct arguments, but I don't know what arguments.

        the

        1 Reply Last reply Reply Quote 0
        • First post
          Last post