qt-dbus类型整理,最近在做dbus的类型,发现关于类型整理并没有详细介绍,总结一下,关于xml文件对应的整理。
基础类型
xml D-Bus 等价类型 Qt DBUS gdbus python
y BYTE uchar dbus.Byte
b BOOLEAN bool dbus.Boolean
n INT16 short dbus.Int16
q UINT16 ushort dbus.UInt16
i INT32 int dbus.Int32
u UINT32 uint dbus.UInt32
x INT64 qlonglong dbus.Int64
t UINT64 qulonglong dbus.UInt64
d DOUBLE double double dbus.Double
s STRING QString gchar * dbus.String dbus.UTF8String(only python2)
v VARIANT QDBusVariant
o OBJECT_PATH QDBusObjectPath dbus.ObjectPath
g SIGNATURE QDBusSignature
as Array of [string] QStringList
QList<QString>
ai Array of [int32] QList<int>
{sv} Dict of {String,Variant} QMap,key为string
value为Variant
a QList
() struct of { } QVariant
{} QMap # 复杂类型
penSUSE imagewriter is a GPL licensed project which contains an example of how to do this. (Relevant files: udisks2_interface.*)
as is Array of [string] . QList<QString> would fit this signature.
a{sv} is a dict of string:variant pairs. QVariantMap would fit this signature.
a{sa{sv}} is a dict of string:a{sv} pairs. QMap<QString, QVariantMap> would fit this signature.
a{oa{sa{sv}}} is a dict of objectpath:a{sa{sv}} pairs. QMap<QDBusObjectPath, QMap<QString, QVariantMap>> would fit this signature.
We should hide those angle-brackets behind some typedefs in a header file:
typedef QMap<QString, QVariantMap> InterfaceList; typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList; Then declare their QMetaTypes in the same header file:
Q_DECLARE_METATYPE(InterfaceList) Q_DECLARE_METATYPE(ManagedObjectList) Then register them with the Qt metatype system at runtime:
qDBusRegisterMetaType(); qDBusRegisterMetaType(); Then we can annotate the XML:
<method name="GetManagedObjects">
<arg type="a{oa{sa{sv}}}" name="objects" direction="out">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ManagedObjectList"/>
</arg>
</method>
<signal name="InterfacesAdded">
<arg type="o" name="object"/>
<arg type="a{sa{sv}}" name="interfaces">
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/>
</arg>
</signal>
xml D-Bus 等价类型 Qt 数据类型
as Array of [string] QList<QString>
a{sv} dict of string QVariantMap
a{sa{sv}} dict of objectpath QMap<QString, QVariantMap>
a{oa{sa{sv}}} dict of objectpath QMap<QDBusObjectPath, QMap<QString, QVariantMap>>