I am trying to get network information (IP address, netmask, route, etc.) for all my interfaces in Qt using the NetworkManager DBus interface. The problem is that when I try to access the "Addresses" property of org.freedesktop.NetworkManager.IP4Config, I get the following error:
QDBusAbstractInterface: type QDBusRawType<0x616175>* must be registered with QtDBus before it can be used to read property org.freedesktop.NetworkManager.IP4Config.Addresses Addresses are invalid Error 2 = "Unregistered type QDBusRawType<0x616175>* cannot be handled"
However, I can get the value of this property using dbus-send with the following command.
dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager \ /org/freedesktop/NetworkManager/IP4Config/0 \ org.freedesktop.DBus.Properties.Get \ string:"org.freedesktop.NetworkManager.IP4Config" \ string:"Addresses"
I can also get good values ββfor the interface property mentioned above via qtdbusviewer. The following is a snippet of code.
QDBusInterface interface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_IFACE, QDBusConnection::systemBus()); // Get a list of all devices QDBusReply<QList<QDBusObjectPath> > result = interface.call("GetDevices"); foreach (const QDBusObjectPath& connection, result.value()) { QDBusInterface device(NM_DBUS_SERVICE, connection.path(), "org.freedesktop.NetworkManager.Device", QDBusConnection::systemBus()); if ( device.property("DeviceType").toInt() == NM_DEVICE_TYPE_ETHERNET ) { // Get the IPv4 information if the device is active if ( device.property("State").toInt() == NETWORK_DEVICE_CONNECTED ) { QVariant ipv4config = device.property("Ip4Config"); if ( ipv4config.isValid() ) { QDBusObjectPath path = qvariant_cast<QDBusObjectPath>(ipv4config); QDBusInterface ifc(NM_DBUS_SERVICE, path.path(), "org.freedesktop.NetworkManager.IP4Config", QDBusConnection::systemBus()); if ( ifc.isValid() ) { qDebug() << "Error 1 = " << ifc.lastError().message(); // No error. Everything is OK. QVariant addresses = ifc.property("Addresses"); // Throwing the QDBusAbstractInterface Error where the property is good and does exist. if ( addresses.isValid() ) { qDebug () << "Addresses are valid"; } else { qDebug () << "Addresses are invalid"; } qDebug() << "Error 2 = " << ifc.lastError().message(); } } } } }
UPDATE # 1
I think this is a type problem. A Qt-Dbus system does not understand the type of the Address property, so it cannot create a QVariant. Therefore, before reading the Address property, I added the following lines. NetworkManager defines the Addresses property as the next type, so I assume that my typedef is good.
aau - "An array of tuples of IPv4 address / prefix / gateway. All 3 elements of each tuple are in network byte order. Essentially: [(addr, prefix, gateway), (addr, prefix, gateway), ...]"
typedef QList<QList<uint> > Addresses; Q_DECLARE_METATYPE(Addresses) qDBusRegisterMetaType<Addresses>() QVariant addresses = ifc.property("Addresses");
I also switched to Qt 5.1 (I used 4.8 before) and I get the same error in the following form.
Cannot construct placeholder type QDBusRawType
Thoughts / Suggestions
Regards, Farrukh Arshad