Reputation: 41
I am new to qt and i have got a question.
I wanted to connect signals and slots.
QObject::connect(_Requests, SIGNAL(newJobsAvailable(const MyClass &)), _Object, SLOT(doSend(const MyClass &)));
The qt complains about not being able to queue MyClass
and etc.
How do i declare it correctly with
qRegisterMetaType<const MyClass &>("const MyClass&");
Upvotes: 1
Views: 670
Reputation: 22890
You need to make sure that MyClass
has public default and copy constructors. Because the object might be copied, even if you declare signals and slots with const ref
.
If for some reason copy is out of the question then pass pointer as suggested by ratchet
Upvotes: 0
Reputation: 37512
If Qt complains about not being able to queue you class this means that, Qt is unable to copy and put inside QVariant object of your class.
This only means that only direct connection will work. What does it mean? If you are using default value of last argument in connect
then connection will not work between threads!
Setting last argument of connect
to Qt::DirectConnection
should silence the warning, and value Qt::QueuedConnection
will not work at all.
Another way to fix it is to register your type. But you should do this without any qualifiers!
qRegisterMetaType<MyClass>("MyClass");
If you are using Qt5 then consider use of Q_GADGET macro in MyClass
(just put it in beginning of class definition and add header to HEADERS in pro file).
Upvotes: 1