Since emitter and receiver objects work in different threads, slots will not be executed synchronously: Qt uses the default connection by default instead of direct connection. However, you can force synchronous execution using a connection with a queue lock (see also http://qt-project.org/doc/qt-4.8/qt.html#ConnectionType-enum for a description of the different types of connections ) when connecting signals and slots.
But connecting to a queue lock has a cost: the emitter flow is blocked until all connected slots are completed, which is not necessarily a good idea. However, if you want to use a non-blocking connection, the execution order depends on whether the slots were executed.
It is important that each QThread has its own event queue. This means that execution order is guaranteed only for slots of a given stream. This means that you must consider the following cases:
- the signal1 slot and the signal2 slot are defined in a QObject living in the same thread: in this case, you can be sure that the slots are executed in the expected order, because they are triggered by the same event queue
- both slots work in different threads: here you do not control the execution order, since the signals are sent to 2 independent event queues. If so, you should use mutexes or wait conditions (or use a blocking connection).
source share