PDA

View Full Version : How could you pass a nested container as an argument to an exposed DBus routine?



digital_aspirin
21st May 2011, 01:08
Hi everyone,
I would like to pass a QVariantList as an argument to a remotely called procedure using DBus. One of the items stored in the container is a QVariantMap which when I attempt to convert it from QVariant to QVariantMap the conversion fails. For instance:



void Ping::sendPing()
{
QVariantMap mPingMap;
mPingMap.insert("key1", "map: Ping says hello");
mPingMap.insert("key2", 456);

QVariantList lPingData;

lPingData << "list: Ping says hello" << 123 << mPingMap;

interfaceCallToPong->test(lPingData);
}

// The remote method:


void Pong::test( QvariantList lRemoteData )
{
qDebug() << lRemoteData.at(0).toString();
qDebug() << lRemoreData.at(1).toInt();


QVariant qvMap = lRemoteData.at(3); // Get the variant that contains the QVariantMap

qvMap.canConvert< QVariantMap > (); // returns false. Why?

// As a result I got no valid data for the following.
QVariantMap mRemoteMap = lRemoteData.at(3).toMap();

qDebug() << mRemoteMap.value("key1").toString ();
qDebug() << mRemoteMat.value("key2").toInt();
}

the output is:
list: Ping says hello
123
0
0

Apparently I am doing something wrong, unless we cannot pass nested containers as an argument to a remotely called procedure using DBus. Could you please help me out?

stampede
21st May 2011, 07:30
lPingData << "list: Ping says hello" << 123 << mPingMap;
///
qDebug() << lRemoteData.at(0).toString();
qDebug() << lRemoreData.at(1).toInt();
QVariant qvMap = lRemoteData.at(3); // are you sure not at(2) ?

For me it looks like the map argument is at index number 2, not 3 :)

digital_aspirin
21st May 2011, 09:01
Yes you are right, it's a typo though. I have also tried to send a QVariantMap which one of its items is a QVariantList but the latter is empty at remote end as well. Although all data can be retrieved at source end before doing the remote procedure call.

stampede
21st May 2011, 14:58
I've just read the QtDbus docs:


All of the QtDBus types (primitives and user-defined alike) can be used to send and receive messages of all types over the bus.
Warning: You may not use any type that is not on the list above, including typedefs to the types listed. This also includes QList<QVariant> and QMap<QString,QVariant>.

Looks like you can't use those types. I have 0 experience with DBus programming, but maybe you can try with QDBusVariant.