In my code I emit a signal (mySignal) and I want to wait for the end of a connected slot (mySlot) execution before it continues:
emit mySignal();
// Wait for the end of mySlot execution...
// Some code that has to be executed only after the end of mySlot execution...
Is there a way to do so ?
If the sender and the receiver are in the same thread use Qt::DirectConnection
, if they are in 2 different threads use Qt::BlockingQueuedConnection
.
ClassA a;
ClassB b;
ClassC c;
c.moveToThread(aThread);
QObject::connect(&a, &ClassA::signal, &b, &ClassB::slot, Qt::DirectConnection);
QObject::connect(&a, &ClassA::signal, &c, &ClassC::slot, Qt::BlockingQueuedConnection);
Please note that you will have to disconnect/reconnect if:
Also Qt::DirectConnection
is the default if the sender and receiver are in the same thread (see Qt::AutoConnection).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With