diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-09-16 12:52:46 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-16 15:22:40 +0200 |
commit | 4bae7158d379acb15a4eae02a4fc3d3e6103a7f9 (patch) | |
tree | 5329c28c59f104015d1b4b465a1634c59267cd3f /tests/auto/corelib | |
parent | 4c19055cb1b077cf161d9cd5c031d711f42a3f25 (diff) |
Don't send posted events from QWindowSystemInterface::sendWindowSystemEvents
The responsibility of sendWindowSystemEvents() is to process events from
the window system. Historially that logic was part of the QPA/QWS event
dispatcher, which naturally also sent posted events. Through refactoring,
the code at some point ended up in in the QWindowSystemInterface class,
still with the posting of events in place.
This resulted in QPA event dispatchers adopting a pattern of just calling
sendWindowSystemEvents(), as that would cover both posted and window system
events. Other event dispatchers would call sendWindowSystemEvents(), and
then use a base-class implementation from QtCore for processing events,
resulting in two calls to QCoreApplication::sendPostedEvents() per
iteration of processEvents(). This breaks the contract that processEvents
will only process posted events that has been queued up until then.
We fix this entanglement by removing the sendPostedEvents() call from
QWindowSystemInterface::sendWindowSystemEvents() and move it to the
respective event dispatchers. For some EDs it means an explicit call
to sendPostedEvents, while others were already doing sendPostedEvents
though a separate source (GLib), or using a base-class (UNIX/BB), and
did not need an extra call.
We still keep the ordering of the original sendWindowSystemEvents()
function of first sending posted events, and then processing any
window system events.
Task-number: QTBUG-33485
Change-Id: I8b069e76cea1f37875e72a034c11d09bf3fe166a
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 93cf799982..8ca785836a 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -78,6 +78,7 @@ private slots: /* void registerEventNotifiier(); */ // Not implemented here, see tst_QWinEventNotifier instead void sendPostedEvents_data(); void sendPostedEvents(); + void processEventsOnlySendsQueuedEvents(); }; bool tst_QEventDispatcher::event(QEvent *e) @@ -207,5 +208,49 @@ void tst_QEventDispatcher::sendPostedEvents() } } +class ProcessEventsOnlySendsQueuedEvents : public QObject +{ + Q_OBJECT +public: + int eventsReceived; + + inline ProcessEventsOnlySendsQueuedEvents() : eventsReceived(0) {} + + bool event(QEvent *event) + { + ++eventsReceived; + + if (event->type() == QEvent::User) + QCoreApplication::postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1))); + + return QObject::event(event); + } +public slots: + void timerFired() + { + QCoreApplication::postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1))); + } +}; + +void tst_QEventDispatcher::processEventsOnlySendsQueuedEvents() +{ + ProcessEventsOnlySendsQueuedEvents object; + + // Posted events during event processing should be handled on + // the next processEvents iteration. + QCoreApplication::postEvent(&object, new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(object.eventsReceived, 1); + QCoreApplication::processEvents(); + QCOMPARE(object.eventsReceived, 2); + + // The same goes for posted events during timer processing + QTimer::singleShot(0, &object, SLOT(timerFired())); + QCoreApplication::processEvents(); + QCOMPARE(object.eventsReceived, 3); + QCoreApplication::processEvents(); + QCOMPARE(object.eventsReceived, 4); +} + QTEST_MAIN(tst_QEventDispatcher) #include "tst_qeventdispatcher.moc" |