Qt::QueuedConnection not working with some object

2k views Asked by At

In my application, we have a simple connection between signal slot.

    connect(&A, SIGNAL(signal(myObject)), &B, SLOT(slot(myObject));

This connection, unfortunately, will lead to a recursion. Then we changed it into

    connect(&A, SIGNAL(signal(myObject)), &B, SLOT(slot(myObject)), Qt::QueuedConnection);

and it does not work anymore. The slot is never called.

I tried changing myObject for a QString and it works as expected. So the problem is something in myObject that Qt does not like so much.

I checked Class Qt.ConnectionType, Signals & Slots and QObject doc, looking for Qt::QueuedConnection but I have not found a clarification for my situation.

Some notes about my code:

  • The myObject is destructed just after the emission of the signal. But it should not be a problem, a copy could have been made (as I suppose is for QString, that has not this problem, I mean, even if I pass a temporary QString and destroy it right after the emission of the signal, the slot is anyway called as expected)

  • myObject is NOT a QObject, and noone of its members are a QObject (if it can have some influence)

  • myObject CAN be copied

  • My application is SINGLE thread

  • myObject has NO default constructor (but I do not think it should influence it, since a copy could be made)

  • I am using Qt 5.7

Does anyone have some clarification for this problem?

Actually, the documentation of Qt::QueuedConnection seems not so detailed, see the links I posted above. Do you have some more useful link?

1

There are 1 answers

6
Phiber On BEST ANSWER

Register your myObject by:

qRegisterMetaType<MyObject>("myObject");

where MyObject is the class name. doc

Between, Qt::QueuedConnection is for connection over threads, your are using threads?