From fda3526f9c6c34f509ebaba67a27e5c32235d7e9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 31 Mar 2025 17:30:09 +0200 Subject: [PATCH] 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 --- tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 41888727c06..5b452a7a1b0 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -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(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