Details
-
Suggestion
-
Resolution: Done
-
P4: Low
-
5.0.0, 5.1.0
-
None
-
Windows, Linux, QtCreator 2.7.2
Description
It it is not possible to define a connection type when connecting a functor/lambda or a function to a signal.
When I try this pseudocode:
// Make the status bar visible: statusBar()->showMessage( "" ); QThread *thread = new QThread; connect( thread, &QThread::started, [this] { statusBar()->showMessage( "Thread started." ); });
then the lambda is connected with Qt::DirectConnection (qobject.h, line 314) for functors and for functions (qobject.h, line 261). This results in an "QCoreApplication::sendEvent: “Cannot send events to objects owned by a different thread"
The typical solution would be to specify Qt::QueuedConnection, which is not possible with the current signature. The problem is that functors/functions don't have a thread affinity, and so it's not possible to determine what kind of event transportation mechanism should be used. But the thread affinity of functors/functions can't be changed and so it should be save to store the thread which is calling connect().