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. Where to put qRegisterMetaType?
Forum Updated to NodeBB v4.3 + New Features

Where to put qRegisterMetaType?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 320 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.
  • A Offline
    A Offline
    angela2016
    wrote on last edited by
    #1

    Hi,

    I've got a signal and slot connection with a custom type called MyMediaInfo. The slot is called in a different thread. My code works with Qt5, but not with Qt6. It says:

    qt.core.qobject.connect: QObject::connect: Cannot queue arguments of type 'MyMediaInfo*'
    (Make sure 'MyMediaInfo*' is registered using qRegisterMetaType().)

    Now, I've run into this problem before, and apparently you have to put these 2 lines somewhere:

    qRegisterMetaType<MyMediaInfo>("MyMediaInfo");
    
    Q_DECLARE_METATYPE(MyMediaInfo)
    

    But WHERE for the love of God do you put this? I've put the

    Q_DECLARE_METATYPE(MyMediaInfo)
    

    bit at the end of the MyMediaInfo header (right before the last #endif).
    The

    qRegisterMetaType<MyMediaInfo>("MyMediaInfo");
    

    bit I've put into the constructor of the class that emits the signal, the class that receives the signal, a general class that is called before everything and even into main.cpp. I've cleaned, rebuilt, deleted the directory, built again. And it still doesn't work. The exact same thing has happened with another class, where - magically - at some point it started working. And I have no idea why.

    What am I supposed to do? I'm losing my mind here. :)

    Best wishes,
    Angela

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Look closely at the error message. It is not complaining about MyMediaInfo, it is complaining about a pointer to MyMediaInfo. So, simply add another registration:

      qRegisterMetaType<MyMediaInfo>("MyMediaInfo");
      qRegisterMetaType<MyMediaInfo*>();
      

      And it should work. Registration should be done before your type is used in any signal-slot connection. So this part you're already doing correctly.

      (Z(:^

      A 1 Reply Last reply
      1
      • sierdzioS sierdzio

        Look closely at the error message. It is not complaining about MyMediaInfo, it is complaining about a pointer to MyMediaInfo. So, simply add another registration:

        qRegisterMetaType<MyMediaInfo>("MyMediaInfo");
        qRegisterMetaType<MyMediaInfo*>();
        

        And it should work. Registration should be done before your type is used in any signal-slot connection. So this part you're already doing correctly.

        A Offline
        A Offline
        angela2016
        wrote on last edited by
        #3

        @sierdzio Grrr, I would never have thought that makes a difference, but you're right. It works now. Thanks so much. :)

        1 Reply Last reply
        0
        • A angela2016 has marked this topic as solved on
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yeah, everybody got bitten by this at least a few times :-)

          (Z(:^

          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