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>
This commit is contained in:
parent
9572dec3d7
commit
a8df998290
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user