QCocoaWindow: be more careful when flushing events

Flushing the QPA event queue is problematic since we can then end up
delivering several events to Qt (or the app) at the same time on the
call stack. This again can easily leave objects in an inconsistent
state if they receive callbacks from subsequent events while being
occupied processing the first.

This is also what happens in the listed report. A QMenu shows
a sub menu when the mouse enters a menu item. The show leads to
QPA flushing events, which in some cases also includes flushing
another pending move event. The move event is delivered to the
same QMenu, which will clear a private variable (currentAction).
When the show returns, the state of QMenu has unexpectedly
changed, which causes a crash to happen since currentAction is
null.

This patch will fix the root cause of the problem by
stopping QCocoaWindow from flushing user input events when
the call location does a flush to deliver geometry events.

Task-number: QTBUG-66093
Change-Id: Id277550b0a080ad98c81e8c30dc7098dc73723d5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2018-02-07 14:08:17 +01:00 committed by Jani Heikkinen
parent ea6675374f
commit 75c22d4598

View File

@ -1131,7 +1131,7 @@ void QCocoaWindow::handleGeometryChange()
// Guard against processing window system events during QWindow::setGeometry
// calls, which Qt and Qt applications do not expect.
if (!m_inSetGeometry)
QWindowSystemInterface::flushWindowSystemEvents();
QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
}
void QCocoaWindow::handleExposeEvent(const QRegion &region)