Home > Software design >  What will the order of slot execution if two signals are emitted at the same time in same thread?
What will the order of slot execution if two signals are emitted at the same time in same thread?

Time:07-21

I am trying to understand the code of HMI (QT based application). Typically in a embedded software, multiple ECUs send data at the same time to the UI.

In which order 2 different slots (2 different UI classes) connected to 2 different signals, be executed if both the signals are triggered at same time within the same thread?

Are they being executed in parallel ? (I guess not possible since there is only 1 thread in picture)

CodePudding user response:

UI classes should be typically handled in your main thread and only heavy computation that can block the UI in worker threads.

So, by default, you would get them executed subsequently, and cannot certainly be in parallel in an ideal design.

Yes, you are right, there is no parallelism with a single thread.

Even with multiple threads involved, you would only ever see true parallelism if the receivers are in different threads.

For further information on various connection types, please refer to the official Qt documentation.

CodePudding user response:

In which order 2 different slots (2 different UI classes) connected to 2 different signals, be executed if both the signals are triggered at same time within the same thread?

When two signals are being emitted from the same thread, it is not possible to be emitted simultaneously. So the signals are being emitted one after another.

Order of slots execution is same as order of signals emission, when Qt::DirectConnection is used, or if both the receiver objects are in the same thread as the sender.

It is always recommended not to depend on the order of slot execution.

  • Related