Results 1 to 4 of 4

Thread: QtDBus: Using <QMap<QString, QString> results in compile error

  1. #1
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QtDBus: Using <QMap<QString, QString> results in compile error

    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:

    Qt Code:
    1. <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QMap&lt;QString,QString>"/>
    2. <arg direction="out" type="a{ss}" name="contents" />
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. typedef QMap<QString,QString> StringMap;
    2. Q_DECLARE_METATYPE(StringMap)
    3.  
    4. qDBusRegisterMetaType<StringMap>();
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. /usr/include/QtCore/qmetatype.h:169:80: error: ‘qt_metatype_id’ is not a member of ‘QMetaTypeId<QMap<QString, QString> >’
    To copy to clipboard, switch view to plain text mode 

    So what am I doing wrong?
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtDBus: Using <QMap<QString, QString> results in compile error

    http://doc.qt.io/qt-4.8/qmetatype

    maybe you need qRegisterMetaType instead of q_declare_metatype
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtDBus: Using <QMap<QString, QString> results in compile error

    Nope, when I put that in front of the qDBusRegisterMetaType I still get the same error.

  4. #4
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtDBus: Using <QMap<QString, QString> results in compile error

    Ok, the Problem was that the DBus Interface didn't know of the Metatypes. I added the following line to my CMakeLists.txt
    Qt Code:
    1. set_source_files_properties(${mtpd_xml} PROPERTIES INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}"/metatypes.h")
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2011, 15:42
  2. I Want to sort QList<QMap<QString , qreal > >
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2011, 13:33
  3. QMAP<QString, QStringList>
    By bismitapadhy in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2010, 04:47
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. QString in Visual Studio 2005 has compile error
    By KaKa in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2007, 10:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.