From fe0f807e1f4e7510c6d8cddd848bcbc25e358651 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 11 Nov 2009 13:50:53 +0100 Subject: Make sure posted events are always sent when calling processEvents() on Win32 After 31f1ff910, posted events could be delayed by a previous call to processEvents(). This causes some tests to randomly fail, so bring back the invariant that processEvents() will always call sendPostedEvents() when called "manually" (i.e. not from exec()). Reviewed-by: Prasanth Ullattil --- src/corelib/kernel/qeventdispatcher_win.cpp | 5 +++ .../auto/qcoreapplication/tst_qcoreapplication.cpp | 36 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 3050b82..0518e24 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -675,6 +675,11 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) bool seenWM_QT_SENDPOSTEDEVENTS = false; bool needWM_QT_SENDPOSTEDEVENTS = false; do { + if (! (flags & QEventLoop::EventLoopExec)) { + // when called "manually", always send posted events + QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); + } + DWORD waitRet = 0; HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1]; QVarLengthArray processedTimers; diff --git a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp index c5f06e2..3c61f81 100644 --- a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp @@ -58,6 +58,7 @@ private slots: #endif void applicationPid(); void globalPostedEventsCount(); + void processEventsAlwaysSendsPostedEvents(); }; class EventSpy : public QObject @@ -488,5 +489,40 @@ void tst_QCoreApplication::globalPostedEventsCount() QCOMPARE(x.globalPostedEventsCount, expected); } +class ProcessEventsAlwaysSendsPostedEventsObject : public QObject +{ +public: + int counter; + + inline ProcessEventsAlwaysSendsPostedEventsObject() + : counter(0) + { } + + bool event(QEvent *event) + { + if (event->type() == QEvent::User) + ++counter; + return QObject::event(event); + } +}; + +void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() +{ + int argc = 1; + char *argv[] = { "tst_qcoreapplication" }; + QCoreApplication app(argc, argv); + + ProcessEventsAlwaysSendsPostedEventsObject object; + QTime t; + t.start(); + int i = 1; + do { + QCoreApplication::postEvent(&object, new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(object.counter, i); + ++i; + } while (t.elapsed() < 3000); +} + QTEST_APPLESS_MAIN(tst_QCoreApplication) #include "tst_qcoreapplication.moc" -- cgit v0.12