Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of slots called on QObject

Tags:

qt

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?

like image 315
Jesse Vogt Avatar asked Aug 07 '09 20:08

Jesse Vogt


People also ask

In what order will the slots be executed if they are connected to one signal?

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.

What are slots and signals in Qt?

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.

How do Qt signals work?

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.


2 Answers

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

like image 136
sepp2k Avatar answered Oct 07 '22 15:10

sepp2k


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

like image 25
Yaroslav Voytovych Avatar answered Oct 07 '22 16:10

Yaroslav Voytovych