[Qt-interest] Signal delivery order?

Frank Hemer frank at hemer.org
Wed Jul 14 17:47:19 CEST 2010


On Wednesday 14 July 2010 17:20:06 Atlant Schmidt wrote:
> Folks:
>
>   I'm trying to understand the order in which signals are delivered to
> slots.
>
>   When I look at:
>
>     http://doc.trolltech.com/4.6.2/signalsandslots.html
>
>   It first says:
>
>     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.
>
>   But later, it seems to take back that promise by saying:
>
>     If on the other hand you want to call two different error functions
> when the number overflows, simply connect the signal to two different
> slots. Qt will call both (in arbitrary order).
>
>
>   Depending on the implementation details, I could believe that, within a
> single thread, either statement is true (that slots are handed the signal
> in the order in which they were originally connected or that slots are
> handed the signals in an arbitrary order); clearly, the second statement
> subsumes the first and it's easier for the trolls if it's the latter. It's
> also safer for me if *I BELIEVE* it's the latter, even if it's sometimes
> the former, but shouldn't the documentation be self-consistent? Does anyone
> know which statement ("connection order" vs. "arbitrary order") is more
> true? And can you correct the documentation? ;-)
>
>   Meanwhile, I also wonder about the delivery order when multiple signals
> are emitted. Can we take it on faith that if a single thread emits the
> signals A, B, and C in that order, they will be delivered to a single slot
> in a single thread in the same order? How about if they are delivered to
> different (multiple) slots in the same thread? Still A, B, then C, no
> matter which slot they're targetting?
>
>   Note: I understand that most of the ordering promises won't hold any time
>   signals are delivered to different threads; one doesn't know when the
> individual threads will actually be "runnable" so that they can receive the
> signals at their slots. But I would still expect that multiple signals
> emitted from one thread and targeting a single thread will be delivered to
> that thread in the order in which they were originally emitted.

Your expectation (multiple signals from one thread, targeting a single thread) 
is correct, no matter if you address one or multiple slots.

Frank



More information about the Qt-interest-old mailing list