summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-02-11 17:53:32 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-13 20:42:40 +0000
commit73f33e4da002b5dc15ad903b0488a833a9a3e758 (patch)
tree67f99b4e9e4b603b86bfcf02d68469bd5f69a78a /tests
parent4768b58f096c27edd495a7ad6620939637804351 (diff)
QMenu: guard for destruction when emitting action signals
If a slot connected to a QMenu-action destroys the QMenu, then we must not touch data members in subsequent code, and instead return immediately. We cannot use QBoolBlocker here, as that would reset the data member of QMenuPrivate even when trying to return early. Fixes: QTBUG-106718 Change-Id: I6b5ea471b1bf1f9864e1384382100f8f6c01346f Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 52ce4d2d29db8a44fa2fa817cab9ebe969db082e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index c73635b83f..c17980e2e3 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -135,6 +135,7 @@ private slots:
void tearOffMenuNotDisplayed();
void QTBUG_61039_menu_shortcuts();
void screenOrientationChangedCloseMenu();
+ void deleteWhenTriggered();
protected slots:
void onActivated(QAction*);
@@ -1977,5 +1978,22 @@ void tst_QMenu::screenOrientationChangedCloseMenu()
QTRY_COMPARE(menu.isVisible(),false);
}
+/*
+ Verify that deleting the menu in a slot connected to an
+ action's triggered signal doesn't crash.
+ QTBUG-106718
+*/
+void tst_QMenu::deleteWhenTriggered()
+{
+ QPointer<QMenu> menu = new QMenu;
+ QAction *action = menu->addAction("Action", [&menu]{
+ delete menu;
+ });
+ menu->popup(QGuiApplication::primaryScreen()->availableGeometry().center());
+ menu->setActiveAction(action);
+ QTest::keyClick(menu, Qt::Key_Return);
+ QTRY_VERIFY(!menu);
+}
+
QTEST_MAIN(tst_QMenu)
#include "tst_qmenu.moc"