#include <QApplication>
#include <QWidget>
#include <QDBusConnection>
#include <QDebug>
class Window: public QWidget
{
public:
Window(){}
void slot(QString str, QVariantMap map, QStringList list)
{
qDebug() << str << map << list;
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window *win = new Window();
QDBusConnection con = QDBusConnection::sessionBus();
bool result = con.connect("org.mpris.MediaPlayer2.chromium.instance14494",
"/org/mpris/MediaPlayer2",
"org.freedesktop.Properties",
"PropertiesChanged", win, SLOT(slot(QString, QVariantMap, QStringList)));
qDebug() << result;
return app.exec();
}
QDBUS_DEBUG=1 启动程序时
我得到以下信息:
QDBusConnectionPrivate(0x7fb450003a00) : connected successfully
QDBusConnectionPrivate(0x7fb450003a00) got message (signal): QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.1735") )
QDBusConnectionPrivate(0x7fb450003a00) delivery is suspended
false
QDBusConnectionPrivate(0x7fb450003a00) dequeueing message QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.1735") )
在浏览器中切换音乐曲目时,终端中的输出没有变化,dbus-monitor 显示 PropertiesChanged 信号如何抽动。
我也知道org.mpris.MediaPlayer2.chromium.instance14494
重启Chromium后,最后数字变了,我用vlc试了一下,结果是一样的。