[Development] Why is QSignalSpy using Qt::DirectConnection?

Roland Winklmeier roland.m.winklmeier at gmail.com
Fri Oct 24 15:41:20 CEST 2014


Dear list,

quick question: I spotted the class QSignalSpy while writing unit tests for
one of my projects. There was nothing written in the documentation, that it
is not thread safe and had assumed it is. So I connected signals from a
QObject running in a different thread and got several warnings (timers
cannot be killed, etc).
After inspecting its header file, I saw the usage of Qt::DirectConnection.

if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
Qt::DirectConnection, 0)).

I wonder now if this is intended or the two occurrences can be changed to
Qt::AutoConnection.

if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
Qt::AutoConnection, 0)).

That should make the class pretty thread safe, no?
There is even a suggestion report:
https://bugreports.qt-project.org/browse/QTBUG-40616.
If you guys are happy, I'll send the patch to gerrit. But before doing it,
I wanted to check with you, if there is anything I might have missed.

Cheers
Roland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141024/4cb63541/attachment.html>


More information about the Development mailing list