Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use qRegisterMetaType to solve this issue?
Qt 6.11 is out! See what's new in the release blog

How to use qRegisterMetaType to solve this issue?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    Originally I was passing a pointer to a type to signals which worked, the slots obviously had to returned the same pointer, again this worked.

    However I thought it would be safer and an improvement to pass a reference instead. However this results in the message:

    QObject::connect: Cannot queue arguments of type 'QJsonObject&'
    (Make sure 'QJsonObject&' is registered using qRegisterMetaType().)
    

    So I looked at the documentation for qRegisterMetaType and added:

    void clsJSON::typeRegistration() {
       qRegisterMetaType<QJsonObject&>("QJsonObject&");
    }
    

    This doesn't compile and results in:

    /Users/sy/XMLMPAM/clsJSON.cpp:301: error: no matching function for call to 'qRegisterMetaType'
    ../clsJSON.cpp:301:4: error: no matching function for call to 'qRegisterMetaType'
       qRegisterMetaType<QJsonObject&>("QJsonObject&");
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1884:5: note: candidate template ignored: substitution failure [with T = QJsonObject &]: 'dummy' declared as a pointer to a reference of type 'QJsonObject &'
    int qRegisterMetaType(const char *typeName
        ^
    ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1933:43: note: candidate template ignored: substitution failure [with T = QJsonObject &]: 'type name' declared as a pointer to a reference of type 'QJsonObject &'
    QT_DEPRECATED inline Q_DECL_CONSTEXPR int qRegisterMetaType(T *)
                                              ^                   ~
    ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1921:29: note: candidate function template not viable: requires 0 arguments, but 1 was provided
    inline Q_DECL_CONSTEXPR int qRegisterMetaType()
                                ^
    

    I have already included:

        #include <QMetaType>
    

    How do I resolve the initial problem or do I have to stick with a pointer? I really don't want to pass the entire QJsonObject on the stack so a pointer or reference is preferable.

    I then tried:

    typedef QJsonObject& rQJsonObject;
    

    and:

    qRegisterMetaType<rQJsonObject>("rQJsonObject");
    

    With this:

    no matching function for call to 'qRegisterMetaType'
    

    Appears to the right of the line.

    Kind Regards,
    Sy

    JKSHJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      Originally I was passing a pointer to a type to signals which worked, the slots obviously had to returned the same pointer, again this worked.

      However I thought it would be safer and an improvement to pass a reference instead. However this results in the message:

      QObject::connect: Cannot queue arguments of type 'QJsonObject&'
      (Make sure 'QJsonObject&' is registered using qRegisterMetaType().)
      

      So I looked at the documentation for qRegisterMetaType and added:

      void clsJSON::typeRegistration() {
         qRegisterMetaType<QJsonObject&>("QJsonObject&");
      }
      

      This doesn't compile and results in:

      /Users/sy/XMLMPAM/clsJSON.cpp:301: error: no matching function for call to 'qRegisterMetaType'
      ../clsJSON.cpp:301:4: error: no matching function for call to 'qRegisterMetaType'
         qRegisterMetaType<QJsonObject&>("QJsonObject&");
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1884:5: note: candidate template ignored: substitution failure [with T = QJsonObject &]: 'dummy' declared as a pointer to a reference of type 'QJsonObject &'
      int qRegisterMetaType(const char *typeName
          ^
      ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1933:43: note: candidate template ignored: substitution failure [with T = QJsonObject &]: 'type name' declared as a pointer to a reference of type 'QJsonObject &'
      QT_DEPRECATED inline Q_DECL_CONSTEXPR int qRegisterMetaType(T *)
                                                ^                   ~
      ../../Qt/5.15.2/clang_64/lib/QtCore.framework/Headers/qmetatype.h:1921:29: note: candidate function template not viable: requires 0 arguments, but 1 was provided
      inline Q_DECL_CONSTEXPR int qRegisterMetaType()
                                  ^
      

      I have already included:

          #include <QMetaType>
      

      How do I resolve the initial problem or do I have to stick with a pointer? I really don't want to pass the entire QJsonObject on the stack so a pointer or reference is preferable.

      I then tried:

      typedef QJsonObject& rQJsonObject;
      

      and:

      qRegisterMetaType<rQJsonObject>("rQJsonObject");
      

      With this:

      no matching function for call to 'qRegisterMetaType'
      

      Appears to the right of the line.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @SPlatten said in How to use qRegisterMetaType to solve this issue?:

      However I thought it would be safer and an improvement to pass a reference instead.

      This is not true. Passing a reference has the same dangers as passing a pointer.

      How to use qRegisterMetaType to solve this issue?

      You can't use qRegisterMetaType to solve the issue. You pass by const reference instead to solve the issue.

      Also, make sure you understand the top answer at https://stackoverflow.com/questions/2139224/how-to-pass-objects-to-functions-in-c

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3

      • Login

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