DBus reply data accessed via QString
-
@micland
The name of the player is "Clementine" and I am using Qt 4.8 . No worries, thank you a lot for your help anyway. I will keep looking for a solution. If I can't find anything I will use one of the other APIs. Cheers again.@amonR2
out of curiousity I was looking for a solution (I didn't know before that maps and structs are supported by DBus). And I found a way - using Qt 5.6, but should work with Qt 4.8 as well:// first the same code as you did already QDBusInterface *iface_Clementine = new QDBusInterface("org.mpris.clementine", "/Player", "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); if(iface_Clementine->isValid()) { QDBusMessage replyClementine = iface_Clementine->call("GetMetadata"); qDebug() << replyClementine; // there is just one argument and this argument is a map QList<QVariant> args = replyClementine.arguments(); const QDBusArgument &arg = args[0].value<QDBusArgument>(); // the map has to be extracted entry by entry which is a tuple of key and value // in this case, the key is a string but the type of the value depends on the key (string, int, ...) arg.beginMap(); while (!arg.atEnd()) { QString key; QDBusVariant value; arg.beginMapEntry(); arg >> key >> value; arg.endMapEntry(); qDebug() << "Key:" << key << "\t\tValue:" << value.variant(); } arg.endMap(); }
You still have to inspect the type of the value (depends on what the entry represents: album or track number, or whatever). And the argument parsing can be wrapped in a stream operator, see http://doc.qt.io/qt-5/qdbusargument.html#beginMap-1
Some further helpul information can be found here: http://stackoverflow.com/questions/20206376/how-do-i-extract-the-returned-data-from-qdbusmessage-in-a-qt-dbus-call
I have no clue why the qdbusviewer of Qt 5.6 is unable to call the DBus method but the code snippet above is working fine.
-
@amonR2
out of curiousity I was looking for a solution (I didn't know before that maps and structs are supported by DBus). And I found a way - using Qt 5.6, but should work with Qt 4.8 as well:// first the same code as you did already QDBusInterface *iface_Clementine = new QDBusInterface("org.mpris.clementine", "/Player", "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); if(iface_Clementine->isValid()) { QDBusMessage replyClementine = iface_Clementine->call("GetMetadata"); qDebug() << replyClementine; // there is just one argument and this argument is a map QList<QVariant> args = replyClementine.arguments(); const QDBusArgument &arg = args[0].value<QDBusArgument>(); // the map has to be extracted entry by entry which is a tuple of key and value // in this case, the key is a string but the type of the value depends on the key (string, int, ...) arg.beginMap(); while (!arg.atEnd()) { QString key; QDBusVariant value; arg.beginMapEntry(); arg >> key >> value; arg.endMapEntry(); qDebug() << "Key:" << key << "\t\tValue:" << value.variant(); } arg.endMap(); }
You still have to inspect the type of the value (depends on what the entry represents: album or track number, or whatever). And the argument parsing can be wrapped in a stream operator, see http://doc.qt.io/qt-5/qdbusargument.html#beginMap-1
Some further helpul information can be found here: http://stackoverflow.com/questions/20206376/how-do-i-extract-the-returned-data-from-qdbusmessage-in-a-qt-dbus-call
I have no clue why the qdbusviewer of Qt 5.6 is unable to call the DBus method but the code snippet above is working fine.
WOOW!!! Thank you sooo much micland!! It works!!!
I tried a code similar to yours but some data were missing. Just needed to do a very tiny modification on your code:qDebug() << key << value.variant().toString();
or directly
qDebug() << value.variant().toString();
Except it, it is perfect! Thank you again.
@micland said:I have no clue why the qdbusviewer of Qt 5.6 is unable to call the DBus method but the code snippet above is working fine.
I hope it is going to change as I intend to use it or the 5.7 version very soon.
Cheers again.