From 2d05c7a89ec2ca71be1896b4386ba04ecf80152d Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 5 Dec 2024 19:46:08 -0800 Subject: [PATCH] core/menu: correctly handle menu destruction while open --- src/core/qsmenuanchor.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/qsmenuanchor.cpp b/src/core/qsmenuanchor.cpp index 8c9b525..ded8ad0 100644 --- a/src/core/qsmenuanchor.cpp +++ b/src/core/qsmenuanchor.cpp @@ -78,8 +78,17 @@ void QsMenuAnchor::onClosed() { this->platformMenu = nullptr; } - QObject::disconnect(this->mMenu, &QsMenuHandle::menuChanged, this, &QsMenuAnchor::onMenuChanged); - this->mMenu->unrefHandle(); + if (this->mMenu) { + QObject::disconnect( + this->mMenu, + &QsMenuHandle::menuChanged, + this, + &QsMenuAnchor::onMenuChanged + ); + + this->mMenu->unrefHandle(); + } + emit this->closed(); emit this->visibleChanged(); } @@ -109,6 +118,7 @@ bool QsMenuAnchor::isVisible() const { return this->mOpen; } void QsMenuAnchor::onMenuDestroyed() { this->mMenu = nullptr; + this->onClosed(); emit this->menuChanged(); }