[Interest] Signal and Slot mechansim in Qt4.8.x

Bo Thorsen bo at vikingsoft.eu
Fri Aug 8 14:29:18 CEST 2014

Den 08-08-2014 14:03, Till Oliver Knoll skrev:
> Am 08.08.2014 um 12:15 schrieb Giuseppe D'Angelo <giuseppe.dangelo at kdab.com>:
>> Il 08/08/2014 10:51, Bo Thorsen ha scritto:
>>> The order of the slots execution is undefined. You can not rely on it.
>> Generally speaking it *is* defined: slot activation follows the order of the connect() statements (*).
> But, but...!
>> ...
>> (*) It has been finalized, by documenting it, around Qt 4.6. I guess simply too many people were relying on that behaviour
> I was just about to complain ;) Didn't realise that this behaviour
> has been made "official" now :)

Yep, it says so on the internet 
(http://qt-project.org/doc/qt-5/signalsandslots.html) so it must be true :)

> It might be okay if you have a /single/ class connecting to a given
> signal "in a well-defined order". But as soon as slots of multiple
> classes are to be connected to a given signal "in a well-defined
> order" such a design would probably be doomed to fail rather sooner
> than later, IMHO.

As long as your application is single threaded, then the order is 
perfectly well defined. If you think of connections as implementations 
of the visitor pattern with one visitor object in a list of signals, 
then it's not hard to do this. Emitting a signal and the connected slot 
calls are exactly the same as calling any C++ function, so the order is 

The most surprising thing to me is that it took until 4.6 before this 
was documented, since there doesn't seem to be any good reason not to 
implement connects as a list and call these one after the other.


Viking Software
Qt and C++ developers for hire

More information about the Interest mailing list