I have a QObject that has multiple slots connected to one of its signals. Is there an order in which of each of these slots are called when the signal is emitted?
According to Qt documentation: If several slots are connected to one signal, the slots will be executed one after the other, in the order they have been connected, when the signal is emitted.
In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.
The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments.
In Qt v4.5 and earlier: No, the order is undefined as can be seen in the documentation here:
If several slots are connected to one signal, the slots will be executed one after the other, in an arbitrary order, when the signal is emitted.
Edit: From version 4.6 onwards this is no longer true. Now the slots will run in the order they are connected. The relevant paragraph of the current documentation:
If several slots are connected to one signal, the slots will be executed one after the other, in the order they have been connected, when the signal is emitted
According to Qt documentation:
If several slots are connected to one signal, the slots will be executed one after the other, in the order they have been connected, when the signal is emitted.
http://qt-project.org/doc/qt-4.8/signalsandslots.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With