summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-03-07 11:54:53 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-03-08 11:33:48 +0000
commit0dbfa219e704dbccadff9f305817bfd4ef37905b (patch)
treeb8a4192a1b8498f2318edf47e7cc5e612e75bfaf
parent923e7c26fde2bc42d04902441691b7f7667460a7 (diff)
QQuickPlatformMenu: fix crash on exit with submenus
Ensure that we unparent submenus in destroy(), not just in the destructor. Task-number: QTBUG-66889 Change-Id: I18b5fc28ee47a50f511ef4f8cf55cfdcbae9bfec Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/imports/platform/qquickplatformmenu.cpp19
-rw-r--r--src/imports/platform/qquickplatformmenu_p.h2
2 files changed, 17 insertions, 4 deletions
diff --git a/src/imports/platform/qquickplatformmenu.cpp b/src/imports/platform/qquickplatformmenu.cpp
index abbea4e7..0a5ce8e4 100644
--- a/src/imports/platform/qquickplatformmenu.cpp
+++ b/src/imports/platform/qquickplatformmenu.cpp
@@ -216,15 +216,22 @@ QQuickPlatformMenu::~QQuickPlatformMenu()
m_menuBar->removeMenu(this);
if (m_parentMenu)
m_parentMenu->removeMenu(this);
+
+ unparentSubmenus();
+
+ delete m_iconLoader;
+ m_iconLoader = nullptr;
+ delete m_handle;
+ m_handle = nullptr;
+}
+
+void QQuickPlatformMenu::unparentSubmenus()
+{
for (QQuickPlatformMenuItem *item : qAsConst(m_items)) {
if (QQuickPlatformMenu *subMenu = item->subMenu())
subMenu->setParentMenu(nullptr);
item->setMenu(nullptr);
}
- delete m_iconLoader;
- m_iconLoader = nullptr;
- delete m_handle;
- m_handle = nullptr;
}
QPlatformMenu *QQuickPlatformMenu::handle() const
@@ -277,6 +284,10 @@ void QQuickPlatformMenu::destroy()
if (!m_handle)
return;
+ // Ensure that all submenus are unparented before we are destroyed,
+ // so that they don't try to access a destroyed menu.
+ unparentSubmenus();
+
delete m_handle;
m_handle = nullptr;
}
diff --git a/src/imports/platform/qquickplatformmenu_p.h b/src/imports/platform/qquickplatformmenu_p.h
index b5c23b61..14f083dd 100644
--- a/src/imports/platform/qquickplatformmenu_p.h
+++ b/src/imports/platform/qquickplatformmenu_p.h
@@ -189,6 +189,8 @@ private Q_SLOTS:
void updateIcon();
private:
+ void unparentSubmenus();
+
bool m_complete;
bool m_enabled;
bool m_visible;