Not receiving correct D-Bus reply with Qt

327 Views Asked by At

I want to get idle time on Gnome. The following command works when typed into a terminal:

dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime

I'm new to Qt D-Bus and am not sure how to get that same result using QDBusInterface. I have the following code:

QDBusInterface interface( "org.gnome.Mutter.IdleMonitor",
                          "/org/gnome/Mutter/IdleMonitor/Core",
                          "org.gnome.Mutter.IdleMonitor");

QDBusReply<int> reply = interface.call( "GetIdletime");
std::cout << "Reply: " << reply.value() << '\n';

That prints 0 every time. How do I get the correct idle time?

1

There are 1 best solutions below

0
Ricky Kresslein On BEST ANSWER

I was able to get this working by changing the type of QDBusReply to qulonglong. The working code is:

QDBusInterface interface( "org.gnome.Mutter.IdleMonitor",
                          "/org/gnome/Mutter/IdleMonitor/Core",
                          "org.gnome.Mutter.IdleMonitor");

QDBusReply<qulonglong> reply = interface.call("GetIdletime");