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:
- the sender and the receiver end up the the same thread and they previously were not,or you will have a dead lock.
- the sender or the receiver end up in 2 different threads and they previously were in the same thread.
Also Qt::DirectConnection
is the default if the sender and receiver are in the same thread (see Qt::AutoConnection).