Can Qt call two slots at the same time if they are called from the same signal?

If there are two slots in two different streams, and these slots are connected to the signal in the third stream. Can it happen that both slots are called simultaneously by a signal or are they called synchronously every time?

I ask because I want to send some callback data structure (encapsulated using QSharedPointer ) and ask if a locking mechanism is needed inside.

+4
source share
2 answers

Take a look here (official Qt documentation for the Qt signal / slot mechanism for streams).

Each slot is called inside its thread, so I'm sure that anything can happen. You must install a locking mechanism.

0
source

You do not need to block the actual calls of the signals / slots if you use Qt :: QueuedConnection to transfer information to your streams, as the QueuedConnection mechanism handles this in a thread-safe manner.

However, you still need to protect any available memory available to your threads, no matter how they were called. The fact that the third thread emits one signal, causing calls to both slots, will not change this.

+2
source

All Articles