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:
parent
ba73bde66e
commit
014785d853
@ -642,18 +642,25 @@ struct CountedStruct
|
|||||||
QThread *thread;
|
QThread *thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
static QEventLoop _e;
|
static QScopedPointer<QEventLoop> _e;
|
||||||
static QThread *_t = Q_NULLPTR;
|
static QThread *_t = Q_NULLPTR;
|
||||||
|
|
||||||
class StaticEventLoop
|
class StaticEventLoop
|
||||||
{
|
{
|
||||||
public:
|
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()
|
void tst_QTimer::singleShotToFunctors()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
_e.reset(new QEventLoop);
|
||||||
QEventLoop e;
|
QEventLoop e;
|
||||||
|
|
||||||
QTimer::singleShot(0, CountedStruct(&count));
|
QTimer::singleShot(0, CountedStruct(&count));
|
||||||
@ -661,7 +668,7 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
QCOMPARE(count, 1);
|
QCOMPARE(count, 1);
|
||||||
|
|
||||||
QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
|
QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
|
||||||
QCOMPARE(_e.exec(), 0);
|
QCOMPARE(_e->exec(), 0);
|
||||||
|
|
||||||
QThread t1;
|
QThread t1;
|
||||||
QObject c1;
|
QObject c1;
|
||||||
@ -687,7 +694,7 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
QCOMPARE(e.exec(), 0);
|
QCOMPARE(e.exec(), 0);
|
||||||
|
|
||||||
QTimer::singleShot(0, &c2, &StaticEventLoop::quitEventLoop);
|
QTimer::singleShot(0, &c2, &StaticEventLoop::quitEventLoop);
|
||||||
QCOMPARE(_e.exec(), 0);
|
QCOMPARE(_e->exec(), 0);
|
||||||
|
|
||||||
_t->quit();
|
_t->quit();
|
||||||
_t->wait();
|
_t->wait();
|
||||||
@ -721,8 +728,10 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
thread.quit();
|
thread.quit();
|
||||||
thread.wait();
|
thread.wait();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
|
_e.reset();
|
||||||
|
_t = Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
class DontBlockEvents : public QObject
|
class DontBlockEvents : public QObject
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user