PDA

View Full Version : Unmarshal complex type from QDBus



sajmplus
23rd February 2017, 20:20
Hello,

i have problem with unmarshaling complex type from QDBusArgument. Method returns a{sa{sv}}. I declared typedef for this complex type:



typedef QMap<QString, QMap<QString, QVariant>> ConnectionSettings;
Q_DECLARE_METATYPE(ConnectionSettings)


And i'm trying to call method:



ConnectionSettings NetworkConnection::getSettings()
{
QDBusInterface iface(m_serviceName, m_objectPath, m_interfaceName,
SystemBusConnectionFactory::getInstance());

auto msg = iface.call("GetSettings");
qDebug() << msg;
auto retVal = msg.arguments()
.first()
.value<QDBusArgument>();

ConnectionSettings cs;

retVal.beginMap();
while( !retVal.atEnd() ) {
QString key;
QVariantMap value;
retVal.beginMapEntry();
retVal >> key >> value; //This line crashes!
retVal.endMapEntry();
cs.insert(key, value);
qDebug() << key << value;
}
retVal.endMap();

return cs;
}


Unfortunately there is a segfault - debugger show line 331 in qdbusargument.h:



...
template<typename Key, typename T>
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &map)
{
arg.beginMap();
map.clear();
while (!arg.atEnd()) {
Key key;
T value;
arg.beginMapEntry(); // SIGSEGV here!
arg >> key >> value;
map.insertMulti(key, value);
arg.endMapEntry();
}
arg.endMap();
return arg;
}
...


Where should I search for the problem?

anda_skoa
24th February 2017, 11:08
Have you tried separating the two stream reads?

Does it crash on the key or the value?

Cheers,
_

sajmplus
24th February 2017, 11:14
Its crashing on value.

How can I separate stream?

anda_skoa
25th February 2017, 11:06
Maybe try other value types instead of QVariantMap, e.g. maybe it is a QDBusVariant which contains a map.

Or maybe it is possible to handle a nested map by first streaming the key and then calling beginMap() for the inner map, handling it in an inner loop.

Cheers,
_