From ad0d6be77814dcf484f87a1d89bb30b6652dff92 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 25 Mar 2025 18:17:09 +0100 Subject: [PATCH] tst_QMenu: fix memleaks in tearOffMenuNotDisplayed() QActions can be added to many widgets at the same time, so addAction() doesn't reparent them. Having no (QObject) parents, the QAction objects in this test were consequently leaked. Fix by giving them parents. Passing `this` would have worked, but has the drawback that if you run the test twice (by naming it twice on the command line), actions with identical shortcuts would accumulate and potentially change the result. Therefore, add an automatic QObject to act as their parent. This is the minimally-invasive fix. Amends 198225983df9f402bb368b449f1abeea95ff0dce. Pick-to: 6.9 6.8 6.5 Change-Id: I59881b10076ba790502483242f620aeed3e99575 Reviewed-by: Friedemann Kleint --- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index a18a7a017f7..968cf60bc41 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -1982,11 +1982,13 @@ void tst_QMenu::QTBUG_61039_menu_shortcuts() if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) QSKIP("Window activation is not supported"); - QAction *actionKamen = new QAction("Action Kamen"); + QObject reaper; + + QAction *actionKamen = new QAction("Action Kamen", &reaper); #if QT_CONFIG(shortcut) actionKamen->setShortcut(QKeySequence(QLatin1String("K"))); #endif - QAction *actionJoe = new QAction("Action Joe"); + QAction *actionJoe = new QAction("Action Joe", &reaper); #if QT_CONFIG(shortcut) actionJoe->setShortcut(QKeySequence(QLatin1String("Ctrl+J"))); #endif