PDA

View Full Version : QtDBus: Using <QMap<QString, QString> results in compile error



hefeweiz3n
26th July 2012, 12:21
Hi. I have a Project where I am using a DBus Interface that is already specified (See attached sample project for xml). What I do ist, i specify a dictionary of 2 strings as a QMap<QString,QString> with an annotation like this:


<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QMap&lt;QString,QString>"/>
<arg direction="out" type="a{ss}" name="contents" />

I then typedeffed the map and added it as a Metatype as well as registered it with DBus like this:


typedef QMap<QString,QString> StringMap;
Q_DECLARE_METATYPE(StringMap)

qDBusRegisterMetaType<StringMap>();

When trying to compile the attached sample project however I get the following error message:


/usr/include/QtCore/qmetatype.h:169:80: error: ‘qt_metatype_id’ is not a member of ‘QMetaTypeId<QMap<QString, QString> >’

So what am I doing wrong?

amleto
26th July 2012, 14:38
qmetatype

maybe you need qRegisterMetaType instead of q_declare_metatype

hefeweiz3n
26th July 2012, 14:53
Nope, when I put that in front of the qDBusRegisterMetaType I still get the same error.

hefeweiz3n
27th July 2012, 09:30
Ok, the Problem was that the DBus Interface didn't know of the Metatypes. I added the following line to my CMakeLists.txt

set_source_files_properties(${mtpd_xml} PROPERTIES INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}"/metatypes.h")
and put the typedef and Q_DECLARE_METATYPE in said header. Now it works.

For those not using CMAKE: Generate the cpp from the xml using qdbusxml2cpp -i "metatype_declaration.h" your.dbus.xml to include the headerfile.