summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-11-11 12:50:53 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-11-11 13:59:01 (GMT)
commitfe0f807e1f4e7510c6d8cddd848bcbc25e358651 (patch)
tree2311eaefceb27ff6285c1a74990d219fed582e34
parent791c4035c28257e5a8426e6519866546faaf5286 (diff)
downloadQt-fe0f807e1f4e7510c6d8cddd848bcbc25e358651.zip
Qt-fe0f807e1f4e7510c6d8cddd848bcbc25e358651.tar.gz
Qt-fe0f807e1f4e7510c6d8cddd848bcbc25e358651.tar.bz2
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
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp5
-rw-r--r--tests/auto/qcoreapplication/tst_qcoreapplication.cpp36
2 files changed, 41 insertions, 0 deletions
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<MSG> 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"