i have this c++ code that tries to connect to the org.gnome.SettingsDaemon.MediaKeys dbus service and listen to its MediaPlayerKeyPressed signal to get notified when a media key is pressed using qt and qdbus. My code complies and runs but i don't recieve any signals, so if anyone could tell me what exactly am i doing wrong i would be so grateful.
the code:
#include <QtWidgets/QApplication>
#include <QtDBus/QtDBus>
#include <QtWidgets/QLabel>
#include <QtCore/QString>
#include "mediaHandler.h"
#define SERVICE_NAME "org.gnome.SettingsDaemon.MediaKeys"
#define OBJECT_PATH "/org/gnome/SettingsDaemon/MediaKeys"
#define INTERFACE_NAME "org.gnome.SettingsDaemon.MediaKeys"
#define SIGNAL_NAME "MediaPlayerKeyPressed"
void MediaHandler::MediaPlayerKeyPressed(QString name, QString key)
{
qDebug("test %s", name.toStdString().c_str());
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDBusInterface interface(SERVICE_NAME,
OBJECT_PATH,
INTERFACE_NAME,
QDBusConnection::sessionBus());
if (!interface.isValid())
{
qDebug("interface is not valid\n");
qDebug("%s\n", qPrintable(QDBusConnection::sessionBus().lastError().message()));
exit(1);
}
qDebug("interface is valid");
QDBusReply<void> reply = interface.call("GrabMediaPlayerKeys", "test", (unsigned int)0);
if (!reply.isValid())
{
qDebug("Reply was: invalid");
qDebug("%s", qPrintable(reply.error().message()));
exit(1);
}
qDebug("Reply was: valid");
MediaHandler mediaHandler;
if (!QObject::connect(&interface, SIGNAL(MediaPlayerKeyPressed(QString, QString)),
&mediaHandler, SLOT(MediaPlayerKeyPressed(QString, QString))))
{
qDebug("error1:%s",
qPrintable(QDBusConnection::sessionBus().lastError().message()));
}
else
{
qDebug("connected");
}
return app.exec();
}
i tried testing the service with dbus-send using the GrabMediaPlayerKeys method and it works fine, so i think the problem is somewhere in my code.