2014-03-07 129 views
5

當使用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英尺描述:

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)我知道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}}},有人可以幫我明白了嗎?謝謝!

回答

8

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> 
+0

鑑於註釋語法不適用於我(Qt 5.9.2)。作爲問題的作者,我從qdbusxml2cpp得到了同樣的錯誤。 –

+0

_(好吧,因爲我試圖修復答案被拒絕了,我不想發佈全新的答案,只是爲了解決這個完整和完美的答案這個小問題,我不得不寫在這裏修復,在評論中,我在哪裏無法正確格式化代碼。)_ XML語法的必需修改:每個'annotation'標籤應該從'arg'標籤中取出,並且在它之後單獨放置。 **示例:** **而不是** [](http://dummy.url) –