The Qt D-Bus Type System
D-Bus has an extensible type system based on a few primitives and composition of the primitives in arrays and structures. Qt D-Bus implements the interface to that type system through the QDBusArgument class, allowing user programs to send and receive practically every C++ type over the bus.
The primitive types are supported natively by QDBusArgument and need no special customization to be sent or received. They are listed below, along with the C++ class they relate to:
|Qt type||D-Bus equivalent type|
D-Bus specifies three types of aggregations of primitive types that allow one to create compound types. They are
STRUCT and maps/dictionaries.
Arrays are sets of zero or more elements of the same type, while structures are a set of a fixed number of elements, each of any type. Maps or dictionaries are implemented as arrays of a pair of elements, so there can be zero or more elements in one map.
In order to use one's own type with Qt D-Bus, the type has to be declared as a Qt meta-type with the Q_DECLARE_METATYPE() macro and registered with the qDBusRegisterMetaType() function. The streaming operators
operator<< will be automatically found by the registration system.
Qt D-Bus provides template specializations for arrays and maps for use with Qt's container classes, such as QMap and QList, so it is not necessary to write the streaming operator functions for those. For other types, and specially for types implementing structures, the operators have to be explicitly implemented.
See the documentation for QDBusArgument for examples for structures, arrays and maps.
All of the Qt D-Bus types (primitives and user-defined alike) can be used to send and receive messages of all types over the bus.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.