Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QDBus register type `QMap<QString,QString>'
Qt 6.11 is out! See what's new in the release blog

QDBus register type `QMap<QString,QString>'

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xixi_cly
    wrote on last edited by
    #1

    When I use QDBus to call function,it remind me that:
    QDBusMarshaller: type `QMap<QString,QString>' (1045) is not registered with D-BUS. Use qDBusRegisterMetaType to register it
    QDBusConnection: error: could not send message to service "org.ofono" path "/" interface "org.ofono.VoiceCallManager" member "Dail": Marshalling faild: Unregistered type QMap<QString,QString> passed in arguments
    void ofono::Dial() "Marshalling failed: Unregistered type QMap<QString,QString> passed in arguments"

    But I don't konw how to register type `QMap<QString,QString>' .
    Best Wishes.
    code_text

    QDBusInterface interfaceOfono("org.ofono",
                                  "/",
                                  "org.ofono.VoiceCallManager",
                                  QDBusConnection::systemBus());
    
    QDBusMessage msg;
    QList<QVariant> param;
    QMap<QString, QString> map;
    QString number = "xxxxxxxxxxx";
    map.insert("number", number);
    qDebug() << "telephone number: " << number;
    QVariant var = QVariant::fromValue(map);
    msg = interfaceOfono.call(QDBus::Block, "Dail", var);
    
    jsulmJ 1 Reply Last reply
    0
    • X xixi_cly

      When I use QDBus to call function,it remind me that:
      QDBusMarshaller: type `QMap<QString,QString>' (1045) is not registered with D-BUS. Use qDBusRegisterMetaType to register it
      QDBusConnection: error: could not send message to service "org.ofono" path "/" interface "org.ofono.VoiceCallManager" member "Dail": Marshalling faild: Unregistered type QMap<QString,QString> passed in arguments
      void ofono::Dial() "Marshalling failed: Unregistered type QMap<QString,QString> passed in arguments"

      But I don't konw how to register type `QMap<QString,QString>' .
      Best Wishes.
      code_text

      QDBusInterface interfaceOfono("org.ofono",
                                    "/",
                                    "org.ofono.VoiceCallManager",
                                    QDBusConnection::systemBus());
      
      QDBusMessage msg;
      QList<QVariant> param;
      QMap<QString, QString> map;
      QString number = "xxxxxxxxxxx";
      map.insert("number", number);
      qDebug() << "telephone number: " << number;
      QVariant var = QVariant::fromValue(map);
      msg = interfaceOfono.call(QDBus::Block, "Dail", var);
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xixi_cly The error already suggests to use qDBusRegisterMetaType. Did you read its documentation: https://doc.qt.io/qt-5/qdbusargument.html#qDBusRegisterMetaType ? It even has an example.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply
      2
      • jsulmJ jsulm

        @xixi_cly The error already suggests to use qDBusRegisterMetaType. Did you read its documentation: https://doc.qt.io/qt-5/qdbusargument.html#qDBusRegisterMetaType ? It even has an example.

        X Offline
        X Offline
        xixi_cly
        wrote on last edited by
        #3

        @jsulm May I should use Q_DECLARE_METATYPE() first,then register it with qDBusRegisterMetaType<MyClass>();?
        I have tried this:

        #include <QDBusMetaType>
        #include <QMetaType>
        
        Q_DECLARE_METATYPE(QMap(QString, QString))
        qDBusRegisterMetaType<QMap(QString, QString)>();
        

        But it's not right.

        jsulmJ 1 Reply Last reply
        0
        • X xixi_cly

          @jsulm May I should use Q_DECLARE_METATYPE() first,then register it with qDBusRegisterMetaType<MyClass>();?
          I have tried this:

          #include <QDBusMetaType>
          #include <QMetaType>
          
          Q_DECLARE_METATYPE(QMap(QString, QString))
          qDBusRegisterMetaType<QMap(QString, QString)>();
          

          But it's not right.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @xixi_cly said in QDBus register type &#x60;QMap<QString,QString>':

          qDBusRegisterMetaType<QMap(QString, QString)>();

          This is wrong. Should be:

          qDBusRegisterMetaType<QMap<QString, QString>>();
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          X 1 Reply Last reply
          2
          • jsulmJ jsulm

            @xixi_cly said in QDBus register type &#x60;QMap<QString,QString>':

            qDBusRegisterMetaType<QMap(QString, QString)>();

            This is wrong. Should be:

            qDBusRegisterMetaType<QMap<QString, QString>>();
            
            X Offline
            X Offline
            xixi_cly
            wrote on last edited by
            #5

            @jsulm There are also some errors:
            D:\Demo\qt\phonebook\ofono.cpp:11: error: C++ requires a type specifier for all declarations
            D:\Demo\qt\phonebook\ofono.cpp:11: error: template specialization requires 'template<>'

            alt text

            jsulmJ 1 Reply Last reply
            0
            • X xixi_cly

              @jsulm There are also some errors:
              D:\Demo\qt\phonebook\ofono.cpp:11: error: C++ requires a type specifier for all declarations
              D:\Demo\qt\phonebook\ofono.cpp:11: error: template specialization requires 'template<>'

              alt text

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @xixi_cly Then change it to

              qDBusRegisterMetaType<QMap<QString, QString> >();
              

              You seem to use an older C++ compiler, newer compiler can handle >> in template definitions just fine.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              X 1 Reply Last reply
              2
              • jsulmJ jsulm

                @xixi_cly Then change it to

                qDBusRegisterMetaType<QMap<QString, QString> >();
                

                You seem to use an older C++ compiler, newer compiler can handle >> in template definitions just fine.

                X Offline
                X Offline
                xixi_cly
                wrote on last edited by
                #7

                @jsulm Thank you.After put it in the function, I have solved the problem.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved