tst_QGraphicsLinearLayout: fix memleaks in itemAt_visualOrder()

The test function leaked all the items it created.

Unless I renamed the object and kept the pointers to them by their old
names, any fix would touch every line, anyway. The former would be
pretty contrived in such a short function, so port the complete test
to stack-allocated objects, which is how this function would have been
written today.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Ia8a67825d3a80be4574b7779c2105d53003b9e69
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 64060cbeae86b2bfeccc6fc18df56cd1e829b0e7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-27 13:16:50 +01:00 committed by Qt Cherry-pick Bot
parent 25b71e1fee
commit d25185fb0d

View File

@ -655,24 +655,24 @@ void tst_QGraphicsLinearLayout::itemAt()
void tst_QGraphicsLinearLayout::itemAt_visualOrder() void tst_QGraphicsLinearLayout::itemAt_visualOrder()
{ {
QGraphicsLinearLayout *l = new QGraphicsLinearLayout; QGraphicsLinearLayout l;
QGraphicsWidget *w1 = new QGraphicsWidget; QGraphicsWidget w1;
l->addItem(w1); l.addItem(&w1);
QGraphicsWidget *w3 = new QGraphicsWidget; QGraphicsWidget w3;
l->addItem(w3); l.addItem(&w3);
QGraphicsWidget *w0 = new QGraphicsWidget; QGraphicsWidget w0;
l->insertItem(0, w0); l.insertItem(0, &w0);
QGraphicsWidget *w2 = new QGraphicsWidget; QGraphicsWidget w2;
l->insertItem(2, w2); l.insertItem(2, &w2);
QCOMPARE(l->itemAt(0), static_cast<QGraphicsLayoutItem*>(w0)); QCOMPARE(l.itemAt(0), static_cast<QGraphicsLayoutItem*>(&w0));
QCOMPARE(l->itemAt(1), static_cast<QGraphicsLayoutItem*>(w1)); QCOMPARE(l.itemAt(1), static_cast<QGraphicsLayoutItem*>(&w1));
QCOMPARE(l->itemAt(2), static_cast<QGraphicsLayoutItem*>(w2)); QCOMPARE(l.itemAt(2), static_cast<QGraphicsLayoutItem*>(&w2));
QCOMPARE(l->itemAt(3), static_cast<QGraphicsLayoutItem*>(w3)); QCOMPARE(l.itemAt(3), static_cast<QGraphicsLayoutItem*>(&w3));
} }
void tst_QGraphicsLinearLayout::orientation_data() void tst_QGraphicsLinearLayout::orientation_data()