qdbusxml2cpp未知类型
问题描述:
当使用qdbusxml2cpp程序转换下面的XML到一个Qt类,我得到这个错误:qdbusxml2cpp未知类型
qdbusxml2cpp -c ObjectManager -a ObjectManager:ObjectManager.cpp xml/object_manager.xml
Got unknown type `a{oa{sa{sv}}}'
You should add <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="<type>"/> to the XML description
d英尺描述:
XML:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node><interface name="org.freedesktop.DBus.Introspectable"><method name="Introspect"><arg name="xml" type="s" direction="out"/>
</method></interface><interface name="org.freedesktop.DBus.ObjectManager"><method name="GetManagedObjects"><arg name="objects" type="a{oa{sa{sv}}}" direction="out"/>
</method><signal name="InterfacesAdded"><arg name="object" type="o"/>
<arg name="interfaces" type="a{sa{sv}}"/>
</signal>
<signal name="InterfacesRemoved"><arg name="object" type="o"/>
<arg name="interfaces" type="as"/>
</signal>
</interface><node name="org"/></node>
从这个网站(http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes)我知道nd我需要向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 } } }
<arg name="customdata" type="a{sv}" direction="in" />
QVariantMap in the arguments (type "a{sv}")
QMap<QString, QVariant>
但是,我不知道注释应该是什么样的OA {{{SA SV}}},有人可以帮我明白了吗?谢谢!
答
openSUSE imagewriter是一个GPL授权项目,其中包含如何执行此操作的示例。
(相关文件:udisks2_interface.*
)
a{sv}
是字符串的字典:变种对。 QVariantMap
将符合此签名。
a{sa{sv}}
是字符串的字典:a{sv}
对。 QMap<QString, QVariantMap>
会适合这个签名。
a{oa{sa{sv}}}
是对象路径的字典:a{sa{sv}}
对。 QMap<QDBusObjectPath, QMap<QString, QVariantMap>>
将适合这个签名。
我们应该隐藏在头文件中的一些类型定义背后那些尖括号:
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>
鉴于注释语法不适用于我(Qt 5.9.2)。作为问题的作者,我从qdbusxml2cpp得到了同样的错误。 –
_(好吧,因为我试图修复答案被拒绝了,我不想发布全新的答案,只是为了解决这个完整和完美的答案这个小问题,我不得不写在这里修复,在评论中,我在哪里无法正确格式化代码。)_ XML语法的必需修改:每个'annotation'标签应该从'arg'标签中取出,并且在它之后单独放置。 **示例:** **而不是** [ ](http://dummy.url) –