There are many slots in Qt connected to the same signal, are they called ok when emitting a signal?

The doc Qt

says:

if several slots are connected to the same signal, the slots will be executed one after the other, in the order in which they were connected when the signal is emitted.

But in the function connect()

setting the type Qt::ConnectionType

as Qt::QueuedConnection

means "The slot is called when control returns to the event loop of the sink thread. The slot is executed on the sink thread." and Qt::DirectConnection

means "the slot is called immediately when the signal is emitted". Slots may not be running fine.

Are they in conflict?

+3


source to share


2 answers


If multiple slots have Qt::DirectConnection

, they will be called in the order in which they were connected. If multiple slots have Qt::QueueConnection

, they will be called in the order in which they were connected. If you mix and match, then all Qt::DirectionConnection

slots will be called in order, and then when control returns to the event loop, all slots Qt::QueuedConnection

will be called in order.



+5


source


Note, however, that although the order in which the slot is called is known, depending on this it will almost always result in fragile code. Connections must be dynamic. It is quite difficult for them to be dynamic if you depend on the order of the remaining connections. If you have code that really depends on the order of the connection, you must refactor it so that the order of execution is controlled in some other way, or, as you know, the code developer knows that the actions need to be ordered.



+1


source







All Articles