[Qt-interest] Qt::AutoConnection fails
Andreas Pakulat
apaku at gmx.de
Tue Apr 14 18:31:19 CEST 2009
On 14.04.09 15:21:43, Oliver.Knoll at comit.ch wrote:
> Thiago Macieira wrote on Tuesday, April 14, 2009 2:37 PM:
>
> > Em Terça-feira 14 Abril 2009, às 11:25:48, Oliver.Knoll at comit.ch
> > escreveu:
> >> First off, it is important to realise that Qt::AutoConnect decides at
> >> *connection time* whether Qt::QueuedConnection or
> >> Qt::DirectConnection has to be used. It does this by comparing the
> >> threads (http://doc.trolltech.com/4.5/qobject.html#thread) to which
> >> the QObject based object is associated with, at the point where
> >> connect() is called. If both objects reside in the same thread, then
> >> Qt::DirectConnection will be used, otherwise Qt::QueuedConnection.
> >
> > That's actually incorrect.
> >
> > The decision on whether to queue or to deliver directly in the case
> > of an AutoConnection is done at emission time, not at connection
> > time. If either the sender or receiver belong to another thread, the
> > emission is queued.
>
> Oh okay, I should have checked the Qt docs. But I remember that there was a warning somewhere in the Qt 4.0.x docs (or any other Qt related documentation, because honestly I don't find the reference anymore ;), saying that one should pay attention as to *when exactly* call connect(), because it decides *at that time* what kind of connection should be used.
At least in 4.0 there was no such warning from ::connect() and the code
that determines queued vs. direct when Qt::AutoConnection has been used
is also the same in 4.0 as in 4.5.
And your example is incomplete. Wether a direct or queued connection is
used depends on where MyObject is being created, not where the connect
call is placed. If MyObject is created in the MyThread constructor then
it'll be a direct connection because both the thread object as well as
its member are being created inside the "main" thread and hence both
have the same thread as owning thread. If however MyObject is created
inside ::run() then it'll have MyThread as owning thread and hence a
queued connection will be used.
Andreas
--
Excellent time to become a missing person.
More information about the Qt-interest-old
mailing list