diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h
index 9e738d2c4749f346e00a771a90859b342c8e7730..034655cc501f167d8bccabc571d5fece7e70ab7b 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;