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. Receiving system D-Bus events (signals) and responding to them

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 253 Views
  • 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.
  • swirlS Offline
    swirlS Offline
    swirl
    wrote on last edited by
    #1

    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
    0
    • swirlS Offline
      swirlS Offline
      swirl
      wrote on last edited by
      #2

      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
      0

      • Login

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