【问题标题】:qdbusxml2cpp unknown typeqdbusxml2cpp 未知类型
【发布时间】:2014-04-10 19:10:44
【问题描述】:

使用 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-脚描述:

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}}} 的注释应该是什么,有人可以帮我理解吗?谢谢!

【问题讨论】:

    标签: c++ qt dbus qdbus qdbusxml2cpp


    【解决方案1】:

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


    a{sv} 是字符串:变体对的字典。
    QVariantMap 适合此签名。

    a{sa{sv}} 是字符串的字典:a{sv} 对。
    QMap&lt;QString, QVariantMap&gt; 适合此签名。

    a{oa{sa{sv}}} 是 objectpath:a{sa{sv}} 对的字典。
    QMap&lt;QDBusObjectPath, QMap&lt;QString, QVariantMap&gt;&gt; 适合此签名。

    我们应该将这些尖括号隐藏在头文件中的某些 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>
    

    【讨论】:

    • 给定的注释语法对我不起作用(Qt 5.9.2)。我从 qdbusxml2cpp 得到了与问题作者相同的错误。
    • (好的,因为我试图修复答案的尝试被拒绝了,我不想发布全新的答案,只是为了用这个完整而完美的答案来解决这个小问题,我必须在这里写修复,在注释中,我无法正确格式化代码。) 需要修改 XML 语法:每个 annotation 标记应从 arg 标记中取出并单独放在它后面。 示例: />而不是 </arg>
    • @ArtemPisarenko 你的编辑看起来不错,所以我已经批准了,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-01-02
    • 2014-08-17
    • 2020-11-19
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2021-05-11
    • 2013-04-26
    相关资源
    最近更新 更多