How do you add complex types with Qt DBus in Qt5/6

For background:

I’m writing a program that listens for the creation of new IPv4 Config objects in NetworkManager and gets the DHCP-provided gateway and nameservers from the properties of the object. Eventually this code should create host routes to the DNS servers for a little more robustness in some complicated lab setups.

I can get the Gateway property easily enough, but the program crashes as soon as it would reach the line to read the property for Nameservers.

Header:

#ifndef NETMONITOR_H
#define NETMONITOR_H
#include <QtCore>
#include <QtDBus/QDBusInterface>

#define NM_SVC "org.freedesktop.NetworkManager"
#define NM_OBJ_MAIN "/org/freedesktop/NetworkManager"
#define NM_OBJ_MANAGER "/org/freedesktop"
#define NM_IF_MAIN "org.freedesktop.NetworkManager"
#define DBUS_IF_MANAGER "org.freedesktop.DBus.ObjectManager"
#define NM_IF_IPV4CFG "org.freedesktop.NetworkManager.IP4Config"

class NetMonitor : public QObject
{
        Q_OBJECT
private:
public:
        NetMonitor(QObject* parent );
private slots:
        void handleNewInterfaces( QDBusObjectPath f_newObject, QVariantMap f_newInterfaces );

};
#endif

Implementation:

#include <QtCore>
#include <QtDBus/QDBusConnection>
#include <QDBusMetaType>

#include "NetMonitor.h"

typedef QList<uint> NameserverList;
Q_DECLARE_METATYPE(NameserverList)

NetMonitor::NetMonitor( QObject *parent ) : QObject( parent )
{
        qDBusRegisterMetaType<NameserverList>();
        if( ! QDBusConnection::systemBus().connect( QStringLiteral(NM_SVC), QStringLiteral( NM_OBJ_MANAGER ),
                QStringLiteral(DBUS_IF_MANAGER), QStringLiteral("InterfacesAdded"),
                this, SLOT(handleNewInterfaces( QDBusObjectPath, QVariantMap )) ) )
        {
                qInfo() << "Failed to connect InterfacesAdded signal.";
        }
}

void NetMonitor::handleNewInterfaces( QDBusObjectPath f_ipconfig, QVariantMap f_settingsmap ){
        Q_UNUSED(f_settingsmap);
        if( ! f_ipconfig.path().startsWith( QStringLiteral("/org/freedesktop/NetworkManager/IP4Config/") ) ) return;

        qInfo( "New NM Object=%s", qPrintable(f_ipconfig.path()) );

        QDBusInterface newIP4conf ( QStringLiteral(NM_SVC), f_ipconfig.path(), QStringLiteral(NM_IF_IPV4CFG), QDBusConnection::systemBus() );
        qInfo( "Gateway is %s", qPrintable( newIP4conf.property("Gateway").toString() ) );

        NameserverList nameservers = newIP4conf.property("Nameservers").value<NameserverList>();
}

When I run this in the background with Qt DBus Debug messages enabled and turn on networking I get:

QDBusConnectionPrivate(0xf6604750) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.NetworkManager", path="/org/freedesktop/NetworkManager/IP4Config/69", interface="org.freedesktop.DBus.Properties", member="Get", signature="", contents=("org.freedesktop.NetworkManager.IP4Config", "Gateway") )
QDBusConnectionPrivate(0xf6604750) got message reply: QDBusMessage(type=MethodReturn, service=":1.5", signature="v", contents=([Variant(QString): "192.168.0.1"]) )
Gateway is 192.168.0.1
Cannot construct placeholder type QDBusRawType

[1]+  Aborted                 QDBUS_DEBUG=1 ./objmonitor

So the type system doesn’t even know how to prepare to run this call despite my efforts to declare a metatype and just gives up. But it can retrieve the string-type Gateway just fine. And this is the simple example. The non-deprecated property for NameserverData is of type aa{sv}, or a list of dictionaries of variants.

I’ve seen various questions like this before but most seem to end in workarounds or partial self-answers. What I want to know is: in Qt 5, and later 6, what strictly is needed to add each of the complex types to the type system so you can read them from properties, connect to signals that return them, and write them to properties, or use them as the arguments of calls.

Do you need to define new classes for structs?

If you need a list do you define the meta object for the list type or for the contents of the list?

How do you deal with recursive complex types, like the actually VERY common double-string-indexed map of variants a{sa{sv}} ?

Am I going to be stuck manually calling org.freedesktop.DBus.Properties.Get() and then parsing the results out of a QDBusArgument?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật