tst_QTreeView: fix memleak in expandAfterTake()

QStandardItems that were taken out of their QStandardItemModel need to
be deleted by the caller, which this test function forgot to do.

Store the item in a unique_ptr, so it isn't deleted until after the
next populateModel() call. Deleting immediately may change what the
test function checks for.

Amends 6012285e7dedb4364e2db087b7d5cbfc2973320a.

Pick-to: 6.9 6.8 6.5
Change-Id: I45a0a2f598febc75fd9ef683525c973476dcd7e0
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-03-26 16:16:25 +01:00
parent 78e785122b
commit a8c55cb547

View File

@ -5260,7 +5260,7 @@ void tst_QTreeView::expandAfterTake()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
view.expandAll();
model.takeItem(0);
const std::unique_ptr<QStandardItem> reaper{model.takeItem(0)};
populateModel(&model); // populate model again, having corrupted items inside QTreeViewPrivate::expandedIndexes
view.expandAll(); // adding new items to QTreeViewPrivate::expandedIndexes with corrupted persistent indices, causing crash sometimes
}