Trying to use the DBus API with QtDBus - does the example =?UTF-8?Q?work=3F?=

I have hacked up the change-ipv4-address.cpp example in an attempt to make it so that the program takes an interface name such as "eth0" and changes the IP address instead of a UUID.
The problem is:
"Error: could not update connection: org.freedesktop.DBus.Error.UnknownMethod Method "Update" with signature "a{sa{sv}}" on interface "org.freedesktop.NetworkManager.Settings.Connection" doesn't exist"

This comes from a piece of code that I did not change and should work the same as the original - unless I have really misunderstood something. Surfing around using the qdbus tool I noticed that I could not get to the Settings methods. I could only get org.freedesktop.NetworkManager.Device.* stuff.

qdbus --system org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/0 org.freedesktop.NetworkManager.[no Settings methods here!]

Example code:

My code:

#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusReply>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QDebug>
#include <QtNetwork/QHostAddress>

#include "arpa/inet.h"

#include "NetworkManager.h"

typedef QMap<QString, QMap<QString, QVariant> > Connection;
Q_DECLARE_METATYPE(QList<QList<uint> >);

QString ifaceNameToPath(const QString& iface_name){
        // Set up DBus interface to org.freedesktop.NetworkManager
        QDBusInterface interface(

        // Call GetDevicesByIpIface using iface_name
QDBusReply<QDBusObjectPath> path ="GetDeviceByIpIface", iface_name);
        qDebug() << path.value().path();
        // return the path.
        return path.value().path();

void changeConnection(const QString& ifname)
    // Register types with D-Bus
    qDBusRegisterMetaType<QList<uint> >();
    qDBusRegisterMetaType<QList<QList<uint> > >();

    Connection connection;
    QString conPath;

    // Find connection by provided UUID
    conPath = ifaceNameToPath(ifname);
    qDebug() << "Derp conPath " << conPath << " ifname was " << ifname;
    if (!conPath.isEmpty()) {
        QList<QList<uint> > addresses;
        QList<uint> addr1, addr2;

        // Add some addresses
        addr1 << htonl(QHostAddress("").toIPv4Address());
        addresses << addr1;

// Set method to "Manual" and put addresses to the connection map
        connection["ipv4"]["method"] = "manual";
connection["ipv4"]["addresses"] = QVariant::fromValue(addresses);

        QDBusInterface interface(

        // Call Update() D-Bus method to update connection
QDBusReply<void> result ="Update", QVariant::fromValue(connection));
        if (result.isValid()) {
qDebug() << QString("Connection successfully updated (path %1)").arg(conPath);
        } else {
qDebug() << QString("Error: could not update connection: %1 %2").arg(result.error().name()).arg(result.error().message());
    } else {
qDebug() << QString("Error: connection with name '%1' not found").arg(ifname);

int main(int argc, char *argv[])
    if (argc != 2) {
        qDebug() << QString("Usage: %1 <UUID>").arg(argv[0]);
        return -1;


--Daniel Devine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]