c++ - qdbusxml2cpp 未知类型

标签 c++ qt dbus qdbus qdbusxml2cpp

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

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 脚说明:

enter image description here

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 ) 我了解到我需要向 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>

但是,我不确定 a{oa{sa{sv}}} 的注释应该是什么,有人可以帮我理解吗?谢谢!

最佳答案

openSUSE imagewriter是一个 GPL 许可项目,其中包含如何执行此操作的示例。
(相关文件:udisks2_interface.*)


a{sv}是 string:variant 对的字典。
QVariantMap适合这个签名。

a{sa{sv}}是字符串的字典:a{sv}对。
QMap<QString, QVariantMap>适合这个签名。

a{oa{sa{sv}}}是对象路径的字典: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"/>
</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"/>
</signal>

关于c++ - qdbusxml2cpp 未知类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22253458/

相关文章:

c++ - 在循环中使用自动 C++

c++ - QFileDialog:保存文件时自动添加扩展名?

c++ - BlueZ D-Bus C 或 C++ 示例

python - 使用 Python-dbus 在 dbus 上发射信号

c - DBUS 服务器崩溃

c++ - 带有特殊字符的字符串的控制台输出

c++ - 无需复制即可将 OpenCV Mat 导入 C++ Tensorflow

c++ - 在 Qt 中,如何将 Unicode 代码点 U+1F64B 转换为包含等效字符 "🙋"的 QString?

c++ - 调用方法后应用程序崩溃

c++ - 如何编写同时接受 && 和 const& 的模板函数?