[英]qdbusxml2cpp unknown type
While using the qdbusxml2cpp program to convert the following xml to a Qt Class, I am getting this error:在使用 qdbusxml2cpp 程序将以下 xml 转换为 Qt Class 时,我收到此错误:
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-Feet description: D-脚说明:
XML: 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>
From this website (http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes ) I understand that I need to add an annotation to the XML for the tool to work properly.从这个网站(http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes )我了解到我需要在 XML 中添加注释才能使该工具正常工作。
Here is what I have so far:这是我到目前为止所拥有的:
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>
However, I'm not sure what the annotation should be for a{oa{sa{sv}}}, can someone please help me understand?但是,我不确定 a{oa{sa{sv}}} 的注释应该是什么,有人可以帮我理解吗? Thanks!谢谢!
openSUSE imagewriter is a GPL licensed project which contains an example of how to do this. openSUSE imagewriter是一个GPL许可项目,其中包含如何执行此操作的示例。
(Relevant files: udisks2_interface.*
) (相关文件: udisks2_interface.*
)
a{sv}
is a dict of string:variant pairs. a{sv}
是字符串:变体对的字典。
QVariantMap
would fit this signature. QVariantMap
适合此签名。
a{sa{sv}}
is a dict of string: a{sv}
pairs. a{sa{sv}}
是字符串的字典: a{sv}
对。
QMap<QString, QVariantMap>
would fit this signature. QMap<QString, QVariantMap>
将适合此签名。
a{oa{sa{sv}}}
is a dict of objectpath: a{sa{sv}}
pairs. a{oa{sa{sv}}}
是objectpath的a{sa{sv}}
词: a{sa{sv}}
对。
QMap<QDBusObjectPath, QMap<QString, QVariantMap>>
would fit this signature. QMap<QDBusObjectPath, QMap<QString, QVariantMap>>
将适合此签名。
We should hide those angle-brackets behind some typedefs in a header file: 我们应该在头文件中隐藏一些typedef后面的尖括号:
typedef QMap<QString, QVariantMap> InterfaceList;
typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
Then declare their QMetaTypes in the same header file: 然后在同一个头文件中声明他们的QMetaTypes:
Q_DECLARE_METATYPE(InterfaceList)
Q_DECLARE_METATYPE(ManagedObjectList)
Then register them with the Qt metatype system at runtime: 然后在运行时使用Qt元类型系统注册它们:
qDBusRegisterMetaType<InterfaceList>();
qDBusRegisterMetaType<ManagedObjectList>();
Then we can annotate the XML: 然后我们可以注释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>
I had the same probleme with newer version (Qt5.12).我对较新版本(Qt5.12)有同样的问题。 I didn't wanted to modify generated code and found out how to generate code properly.我不想修改生成的代码并了解如何正确生成代码。
qdbusxml2cpp didn't know how to deal with dictionary signatures, for me.对我来说,qdbusxml2cpp 不知道如何处理字典签名。 So I add the annotations directly with the Qt types.所以我直接用 Qt 类型添加注释。 like this, for像这样,对于"a{oa{sa{sv}}}" -> QMap<QDBusObjectPath, QMap<QString, QVariantMap> >
<method name="GetManagedObjects">
<arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QMap<QDBusObjectPath,QMap<QString,QVariantMap>>"/>
</method>
With < fot < and > fot >.使用 < fot < 和 > fot >。 Then the code generated is correct.那么生成的代码是正确的。
Hope this will help someone, one day... after 8 years希望这对某人有所帮助,有一天...... 8年后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.