Commit a8df9982 authored by Roland Winklmeier's avatar Roland Winklmeier
Browse files

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: default avatarThiago Macieira <thiago.macieira@intel.com>
parent 9572dec3
No related merge requests found
Showing with 7 additions and 0 deletions
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <QtCore/qeventloop.h> #include <QtCore/qeventloop.h>
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtCore/qpointer.h> #include <QtCore/qpointer.h>
#include <QtCore/qthread.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
...@@ -101,6 +102,12 @@ inline void QTestEventLoop::enterLoopMSecs(int ms) ...@@ -101,6 +102,12 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
inline void QTestEventLoop::exitLoop() inline void QTestEventLoop::exitLoop()
{ {
if (thread() != QThread::currentThread())
{
QMetaObject::invokeMethod(this, "exitLoop", Qt::QueuedConnection);
return;
}
if (timerId != -1) if (timerId != -1)
killTimer(timerId); killTimer(timerId);
timerId = -1; timerId = -1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment