Though Qt::QueuedConnection or Qt::AutoConnection (in certain cases) are preferred in a multithreaded environment, I am asking this question for my understanding purpose.
If signal
MySignal()is emitted in thread A & slotMySlot()belongs to object of thread B. Both are connected viaQt::DirectConnection, how does the execution happen? i.e. If thread A sends a signal to thread B, while thread B is executing in middle of some functionfoo(). Will the slotMySlot()be called just after thefoo()finishes or will it be called in parallel tofoo()?Are there any scenario when
Qt::DirectConnectionis desirable over others in a multithreaded app?
Unfortunately (and as you suspect)
Qt::DirectConnectionis precisely that andB::MySlot()will be invoked on thread A concurrently with whatever is already happening on thread B --foo()in this case. So, without any other form of synchronization the use ofQt::DirectConnectionis generally a bad idea when the sender and receiver may be on different threads.If you really do require the concept of a synchronous cross-thread signal/slot call then you might want to look at
Qt::BlockingQueuedConnection