tst_QButtonGroup: fix memleak in keyNavigationPushButtons()

While a QButtonGroup is-a QObject, unless it has a QObject-parent, it
won't be deleted by, say, the parent of the buttons it contains, so
this test function leaked the QButtonGroup.

Fix by giving it the dialog as parent. This is just a QObject
parent-child relationship; it does not change the behavior of the
button group, nor the dialog, except that the latter now deletes the
former as its QObject child when it itself it deleted.

Amends e7cff5bca7aefaea63e80598babf6bd7917aa1c3.

Pick-to: 6.8 6.5 5.15
Change-Id: Ic633179252c72e7ee47a57be73944a6aa589637b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit ccd0ea0b4e402f02dee73c211d62cef70d3e001f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-26 22:04:03 +01:00 committed by Qt Cherry-pick Bot
parent e014490142
commit 4c769f92a8

View File

@ -197,7 +197,7 @@ void tst_QButtonGroup::keyNavigationPushButtons()
layout->addWidget(pb3);
layout->addWidget(le2);
QButtonGroup *buttonGroup = new QButtonGroup;
QButtonGroup *buttonGroup = new QButtonGroup(&dlg);
buttonGroup->addButton(pb1);
buttonGroup->addButton(pb2);
buttonGroup->addButton(pb3);