Where to put qRegisterMetaType?
-
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).
TheqRegisterMetaType<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 -
Look closely at the error message. It is not complaining about
MyMediaInfo
, it is complaining about a pointer toMyMediaInfo
. 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.
-
Look closely at the error message. It is not complaining about
MyMediaInfo
, it is complaining about a pointer toMyMediaInfo
. 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.
@sierdzio Grrr, I would never have thought that makes a difference, but you're right. It works now. Thanks so much. :)
-
-
Yeah, everybody got bitten by this at least a few times :-)