summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoland Winklmeier <Roland.M.Winklmeier@gmail.com>2014-10-27 23:09:06 +0100
committerRoland Winklmeier <Roland.M.Winklmeier@gmail.com>2014-10-31 22:18:34 +0100
commita8df9982901a8e9d01cce06c9ffe2b34e6ea23a7 (patch)
treed0d7a08f86e9dc58920edfe0cda704f9fca8a87d /src
parent9572dec3d72582bf99266af00a62028518d99852 (diff)
Make QTestEventLoop::exitLoop() thread-safe
QTestEventLoop::exitLoop() is used by QSignalSpy to stop event processing when the connected signal has been received. The design of QSignalSpy requires QTestEventLoop::exitLoop() to be thread-safe, which it wasn't. When QSignalSpy is connected to a signal in a different thread, exitLoop() was called from the thread which emitted the signal and not the one in which QTestEventLoop is running. This caused troubles when killing the internal timer. This patch adds a check in the beginning of exitLoop(). If it is called from a different thread, it will post an event into the message queue in which QTestEventLoop is running and execute it there. Change-Id: Icb8c8ff2f5344800ee6c6125b98c677c7a196c32 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtesteventloop.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h
index 9e738d2c47..034655cc50 100644
--- a/src/testlib/qtesteventloop.h
+++ b/src/testlib/qtesteventloop.h
@@ -40,6 +40,7 @@
#include <QtCore/qeventloop.h>
#include <QtCore/qobject.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qthread.h>
QT_BEGIN_NAMESPACE
@@ -101,6 +102,12 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
inline void QTestEventLoop::exitLoop()
{
+ if (thread() != QThread::currentThread())
+ {
+ QMetaObject::invokeMethod(this, "exitLoop", Qt::QueuedConnection);
+ return;
+ }
+
if (timerId != -1)
killTimer(timerId);
timerId = -1;