tst_QComboBox: fix memleaks in setItemDelegate()/task253944_itemDelegateIsReset()

QItemDelegates are owned by neither the QComboBox directly, nor the
QComboBox::view(), upon a mere setItemDelegate() (the docs of this
function is pretty clear about that). Since the objects didn't have a
QObject parent, either, they were leaked.

To fix, give it the comboBox as a parent.

Amends the start of the public history.

Pick-to: 6.9 6.8 6.5 5.15
Change-Id: Ic8bc2603072070b458bd79a6129af6c76811f8ec
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-03-31 17:30:09 +02:00
parent 0de7cafabc
commit fda3526f9c

View File

@ -2662,7 +2662,7 @@ void tst_QComboBox::noScrollbar()
void tst_QComboBox::setItemDelegate()
{
QComboBox comboBox;
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate;
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(&comboBox);
comboBox.setItemDelegate(itemDelegate);
// the cast is a workaround for the XLC and Metrowerks compilers
QCOMPARE(static_cast<QStyledItemDelegate *>(comboBox.itemDelegate()), itemDelegate);
@ -2671,7 +2671,7 @@ void tst_QComboBox::setItemDelegate()
void tst_QComboBox::task253944_itemDelegateIsReset()
{
QComboBox comboBox;
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate;
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(&comboBox);
comboBox.setItemDelegate(itemDelegate);
// the casts are workarounds for the XLC and Metrowerks compilers