If I had a class A, where one of its functions does:
void A::func()
{
emit first_signal();
emit second_signal();
}
Assuming that a class B has 2 slots, one connected to first_signal
, and the other to second_signal
, is it guaranteed that the slot that is connected to first_signal
will always be processed before the second_signal
slot?
If you use direct connection type between signals and slots (Qt::DirectConnection) then the answer is yes.
From Qt help system:
When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned. The situation is slightly different when using queued connections; in such a case, the code following the emit keyword will continue immediately, and the slots will be executed later.
You can change default connection type to any of enum Qt::ConnectionType in QObject::connect method.
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