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