Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: Do events get processed in order?

Tags:

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?

like image 299
sivabudh Avatar asked Nov 14 '09 02:11

sivabudh


1 Answers

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.

like image 123
Wildcat Avatar answered Sep 27 '22 15:09

Wildcat