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.9 6.8 6.5 5.15
Change-Id: Ic633179252c72e7ee47a57be73944a6aa589637b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-03-26 22:04:03 +01:00
parent 0e314d3434
commit ccd0ea0b4e

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);