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);
}
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);
}
To copy to clipboard, switch view to plain text mode
// 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();
}
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();
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks