diff options
Diffstat (limited to 'src/imports/platform/qquickplatformmenu.cpp')
-rw-r--r-- | src/imports/platform/qquickplatformmenu.cpp | 19 |
1 files changed, 15 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; } |