[Qt-interest] Qt::AutoConnection fails
Stefan Bisplinghoff
bisplinghoff at hia.rwth-aachen.de
Tue Apr 14 20:46:07 CEST 2009
Oliver.Knoll at comit.ch schrieb:
>
> That's why I *emphasized* the word *receiving* ;) In your case the emitting thread is your worker thread and the *receiving* thread is your "main" thread. And I am pretty sure your "main" thread as a QApplication object, on which you called exec(), right? (Just to make sure).
>
Yes, certainly. :-)
> So yes, in your case your worker thread does *not* need a running event queue. So in case you do have QApplication::exec() called in your "main" thread I don't know why your slot is not being called. How do you figure out anyway? I guess you have some qDebug << "I am called." statement and made sure that stdout/err output is visible on some console (in case you're doing this on Windows)?
>
Yes, tested via qDebug, own output routines and breakpoints.
So, let's summarize what we have:
- AutoConnection decides on emit time, whether the slot is called
directly or queued for execution. In the first case, the slot is called
in the same context as the emit. Queued connections use the event queue
and the context, the connect command took place in.
- The emit inside the database is executed in the worker thread context,
although the database instance has been created in the main thread and
its memory resides also there. The connect of SomeComponent has been
called in the main thread. Therefore the connection should be done in
queued mode (sender and receiver in different threads!)
- Debugging of the emit indicates, that the slot is connected in queued
mode, but is not called, because the condition in qobject.cpp
"if (c.argumentTypes == &DIRECT_CONNECTION_ONLY)"
succeeds and the action is aborted.
- The slot in SomeComponent is only called, if DirectConnection is used
explicitly in the connect command. However, the slot is executed in the
wrong thread context.
More? Solutions? :-)
Regards,
Stefan
More information about the Qt-interest-old
mailing list