diff options
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/platform/qquickplatformmenu.cpp | 19 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformmenu_p.h | 2 |
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; |