tst_QGraphicsLinearLayout: remove remaining memleaks in insertItem()

After the QGraphicsWidgets have been dealt with in a previous commit,
the last leak in the function is that of 'item'.

Fix by holding it in a unique_ptr.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I56986139a2b7865cf367bdd25ccde90d5e1c50ca
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 59b18d07e78be0b57c8bb7c9078e89c686ddf0f3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-27 21:09:46 +01:00 committed by Qt Cherry-pick Bot
parent fcf12e50c9
commit 97bacdaab3

View File

@ -468,18 +468,18 @@ void tst_QGraphicsLinearLayout::insertItem()
for (int i = 0; i < layoutCount; ++i)
layout.addItem(new SubQGraphicsLinearLayout);
QGraphicsLayoutItem *item = nullptr;
std::unique_ptr<QGraphicsLayoutItem> item = nullptr;
if (isWidget)
item = new QGraphicsWidget;
item = std::make_unique<QGraphicsWidget>();
else
item = new SubQGraphicsLinearLayout;
item = std::make_unique<SubQGraphicsLinearLayout>();
QSizeF oldSizeHint = layout.sizeHint(Qt::PreferredSize, QSizeF());
layout.insertItem(insertItemAt, item);
layout.insertItem(insertItemAt, item.get());
QCOMPARE(layout.count(), itemCount + layoutCount + 1);
if (insertItemAt >= 0 && (itemCount + layoutCount >= 0)) {
QCOMPARE(layout.itemAt(insertItemAt), item);
QCOMPARE(layout.itemAt(insertItemAt), item.get());
}
layout.activate();