tst_QTimer::singleShotToFunctors: Allocate static event loop on heap.

Fix warning:
QEventLoop: Cannot be used without QApplication
and occasional crashes on Windows.

Task-number: QTBUG-26406
Change-Id: Ia8b2a4e3d375d1e43f0e66fe64a39af5f9cf4d60
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Dario Freddi <dario.freddi@ispirata.com>
This commit is contained in:
Friedemann Kleint 2014-11-10 14:26:34 +01:00
parent ba73bde66e
commit 014785d853

View File

@ -642,18 +642,25 @@ struct CountedStruct
QThread *thread;
};
static QEventLoop _e;
static QScopedPointer<QEventLoop> _e;
static QThread *_t = Q_NULLPTR;
class StaticEventLoop
{
public:
static void quitEventLoop() { _e.quit(); if (_t) QCOMPARE(QThread::currentThread(), _t); }
static void quitEventLoop()
{
QVERIFY(!_e.isNull());
_e->quit();
if (_t)
QCOMPARE(QThread::currentThread(), _t);
}
};
void tst_QTimer::singleShotToFunctors()
{
int count = 0;
_e.reset(new QEventLoop);
QEventLoop e;
QTimer::singleShot(0, CountedStruct(&count));
@ -661,7 +668,7 @@ void tst_QTimer::singleShotToFunctors()
QCOMPARE(count, 1);
QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
QCOMPARE(_e.exec(), 0);
QCOMPARE(_e->exec(), 0);
QThread t1;
QObject c1;
@ -687,7 +694,7 @@ void tst_QTimer::singleShotToFunctors()
QCOMPARE(e.exec(), 0);
QTimer::singleShot(0, &c2, &StaticEventLoop::quitEventLoop);
QCOMPARE(_e.exec(), 0);
QCOMPARE(_e->exec(), 0);
_t->quit();
_t->wait();
@ -721,8 +728,10 @@ void tst_QTimer::singleShotToFunctors()
thread.quit();
thread.wait();
#endif
}
_e.reset();
_t = Q_NULLPTR;
}
class DontBlockEvents : public QObject
{