diff options
author | Filipe Azevedo <filipe.azevedo@kdab.com> | 2016-08-01 19:01:03 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2016-08-22 09:09:25 +0000 |
commit | f44ef9daf9f0f9db6775fdb6d3fc8703b6ce77e4 (patch) | |
tree | 69b454bd7889bcc5f6d7f8a5029399e90a4a1bcb | |
parent | 5bd57528b5cf7b22a81b1195d90b0a364c0428aa (diff) | |
download | qtquickcontrols-f44ef9daf9f0f9db6775fdb6d3fc8703b6ce77e4.tar.gz |
macOS: Fix native dangling menu still visible on screen and crash
If the parent window gets destroyed while a QtQuick Controls menu is open
the macOS native platform menu is not dismissed and you see a blank
gray rectangle without any text.
Also, at this point the QQmlEngine was already destroyed but it's still
present on the call stack, so you get a crash when the stack unwinds to
the original right mouse click that created the context menu.
Change-Id: I638b0de13734815995d2994e6dd6603bcb0ebefc
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-rw-r--r-- | src/controls/qquickmenu.cpp | 17 | ||||
-rw-r--r-- | src/controls/qquickmenu_p.h | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp index b725bbbf..3c243ba3 100644 --- a/src/controls/qquickmenu.cpp +++ b/src/controls/qquickmenu.cpp @@ -436,6 +436,10 @@ void QQuickMenu1::__popup(const QRectF &targetRect, int atItemIndex, MenuType me // parentWindow may not be a QQuickWindow (happens when using QQuickWidget) if (m_platformMenu) { + if (m_windowConnection) + QObject::disconnect(m_windowConnection); + m_windowConnection = connect(parentWindow, &QWindow::visibleChanged, this, + &QQuickMenu1::platformMenuWindowVisibleChanged, Qt::UniqueConnection); QRectF globalTargetRect = targetRect.translated(m_xOffset, m_yOffset); if (visualItem()) { if (qGuiApp->isRightToLeft()) { @@ -565,6 +569,19 @@ void QQuickMenu1::windowVisibleChanged(bool v) } } +void QQuickMenu1::platformMenuWindowVisibleChanged(bool visible) +{ + if (!visible) { + if (m_windowConnection) { + QObject::disconnect(m_windowConnection); + m_windowConnection = QMetaObject::Connection(); + } + if (m_platformMenu) { + m_platformMenu->dismiss(); + } + } +} + void QQuickMenu1::clearPopupWindow() { m_popupWindow = 0; diff --git a/src/controls/qquickmenu_p.h b/src/controls/qquickmenu_p.h index 576ae5fd..8510efbe 100644 --- a/src/controls/qquickmenu_p.h +++ b/src/controls/qquickmenu_p.h @@ -165,6 +165,7 @@ protected Q_SLOTS: void updateText(); void windowVisibleChanged(bool); + void platformMenuWindowVisibleChanged(bool); private: QQuickWindow *findParentWindow(); @@ -205,6 +206,7 @@ private: QFont m_font; int m_triggerCount; bool m_proxy; + QMetaObject::Connection m_windowConnection; }; QT_END_NAMESPACE |