使用qdbusxml2cpp程序将以下xml转换为Qt类时,我收到此错误:
qdbusxml2cpp -c ObjectManager -a ObjectManager:ObjectManager.cpp xml/object_manager.xml Got unknown type `a{oa{sa{sv}}}' You should addto the XML description
D-Feet描述:
XML:
从这个网站(http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes)我明白我需要在XML中添加一个注释才能使工具正常工作.
这是我到目前为止:
a{oa{sa{sv}}} https://alteeve.ca/w/List_of_DBus_data_types o == A UTF-8 string whose value is a valid DBus object path. array { object_path array { string array { string variant } } }QVariantMap in the arguments (type "a{sv}") QMap
但是,我不确定{oa {sa {sv}}}的注释应该是什么,有人可以帮助我理解吗?谢谢!
openSUSE imagewriter是一个GPL许可项目,其中包含如何执行此操作的示例.
(相关文件:udisks2_interface.*
)
a{sv}
是一个字符串:变体对的字典.
QVariantMap
适合这个签名.
a{sa{sv}}
是字符串的字典:a{sv}
对.
QMap<QString, QVariantMap>
适合这个签名.
a{oa{sa{sv}}}
是objectpath的一个词:a{sa{sv}}
对.
QMap<QDBusObjectPath, QMap<QString, QVariantMap>>
适合这个签名.
我们应该在头文件中隐藏一些typedef后面的尖括号:
typedef QMap<QString, QVariantMap> InterfaceList; typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
然后在同一个头文件中声明他们的QMetaTypes:
Q_DECLARE_METATYPE(InterfaceList) Q_DECLARE_METATYPE(ManagedObjectList)
然后在运行时使用Qt元类型系统注册它们:
qDBusRegisterMetaType<InterfaceList>(); qDBusRegisterMetaType<ManagedObjectList>();
然后我们可以注释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>