本文介绍了qdbusxml2cpp未知类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用qdbusxml2cpp程序将以下xml转换为Qt类时,我收到此错误:

While using the qdbusxml2cpp program to convert the following xml to a Qt Class, I am getting this error:

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描述:

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>

从此网站()我理解我需要添加一个注释到XML

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.

以下是我到目前为止所做的工作:

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>

但是,我不知道{oa {sa {sv} }},有人可以帮我理解吗?谢谢!

However, I'm not sure what the annotation should be for a{oa{sa{sv}}}, can someone please help me understand? Thanks!

推荐答案

是一个GPL许可项目,其中包含如何执行此操作的示例。

(相关文件: udisks2_interface。*

openSUSE imagewriter is a GPL licensed project which contains an example of how to do this.
(Relevant files: udisks2_interface.*)

a {sv} 是字符串的字符串: 。

QVariantMap 将适合此签名。

a{sv} is a dict of string:variant pairs.
QVariantMap would fit this signature.

a { sa {sv}} 是字符串的字符串: a {sv} 对。

a{sa{sv}} is a dict of string:a{sv} pairs.
QMap<QString, QVariantMap> would fit this signature.

a {oa {sa {sv}}}

a{oa{sa{sv}}} is a dict of objectpath:a{sa{sv}} pairs.
QMap<QDBusObjectPath, QMap<QString, QVariantMap>> would fit this signature.

我们应该在头文件中隐藏某些typedef后面的尖括号:

We should hide those angle-brackets behind some typedefs in a header file:

typedef QMap<QString, QVariantMap> InterfaceList;
typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;

然后在同一个头文件中声明它们的QMetaTypes:

Then declare their QMetaTypes in the same header file:

Q_DECLARE_METATYPE(InterfaceList)
Q_DECLARE_METATYPE(ManagedObjectList)


$ b b

然后在运行时向Qt元类型系统注册它们:

Then register them with the Qt metatype system at runtime:

qDBusRegisterMetaType<InterfaceList>();
qDBusRegisterMetaType<ManagedObjectList>();

然后我们可以注释XML:

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>

这篇关于qdbusxml2cpp未知类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 21:40