PDA

View Full Version : Read map type from QDBusArgument



volcano
5th March 2013, 05:04
Hi All,

Here's the code attached



QDBusInterface busInterface(
DBUS_NETWORK_MANAGER_SYSYEM_SERVICE_NAME,
m_strDhcp4Config.toAscii().data(),
DBUS_NETWORK_MANAGER_SYSTEM_PROPERTIES_INTERFACE,
QDBusConnection::systemBus());

QDBusReply< QVariantMap > result = busInterface.call(GETALL,
DBUS_NETWORK_MANAGER_SYSTEM_ACTIVE_DHCP4CONFIG_INT ERFACE);

if(result.isValid())
{
qDebug() << "Success";
QVariantMap propertiesMap = result.value();
QDBusArgument optionsArgument = qvariant_cast<QDBusArgument>(propertiesMap.value("Options"));

propertiesMap.clear();
optionsArgument.beginArray();

while ( !optionsArgument.atEnd() ) {
QVariant key;
QVariant value;
optionsArgument.beginMapEntry();
optionsArgument >> key >> value;
optionsArgument.endMapEntry();
propertiesMap.insert( key, value);
}

optionsArgument.endArray();
}


I get this error "QDBusArgument: write from a read-only object" on the lines "optionsArgument.beginMapEntry();" and "optionsArgument.endMapEntry();"

The response I'm looking to parse is
"{u'broadcast_address': u'10.244.10.255',
u'dhcp_lease_time': u'691200',
u'dhcp_message_type': u'5',
u'dhcp_rebinding_time': u'604800',
u'dhcp_renewal_time': u'345600',
u'dhcp_server_identifier': u'10.244.0.99',
u'domain_name': u'persistent.co.in',
u'domain_name_servers': u'10.244.0.100 10.244.0.99',
u'expiry': u'1363079647',
u'filename': u'smsboot\\x86\\wdsnbp.com',
u'ip_address': u'10.244.10.232',
u'netbios_name_servers': u'10.244.0.100',
u'network_number': u'10.244.10.0',
u'routers': u'10.244.10.1',
u'subnet_mask': u'255.255.255.0'}"

Kindly suggest how can I parse this value appropriately..
Thanks,
Volcano

volcano
5th March 2013, 09:08
Minor error in code


optionsArgument.beginMap();
while ( !optionsArgument.atEnd() ) {
QVariant key;
QVariant value;
optionsArgument.beginMapEntry();
optionsArgument >> key >> value;
optionsArgument.endMapEntry();
propertiesMap.insert( key, value);
}
optionsArgument.endMap();


Kindly suggest me what should I do
Regards,
volcano

anda_skoa
10th March 2013, 09:58
While not directly related to your code, some general ideas:

- have you evaluating using the Qt library for network manager instead of using D-Bus directly?
- assuming network manager has the usual XML interface definition files, how about letting qdbusxml2cpp generate an interface class for you?

Cheers,
_