tst_QGraphicsLayout: fix memleaks in alternativeLayoutItems()

I honestly didn't bother to figure out the ownership relationships
between these items; the QGraphicsView docs don't help much:

> The layout takes ownership of the items. In some cases when the
> layout item also inherits from QGraphicsItem (such as
> QGraphicsWidget) there will be a ambiguity in ownership because the
> layout item belongs to two ownership hierarchies

but asan said that the AnimatedLayoutItem objects were leaked, so hold
them in unique_ptrs now.

Amends the start of the public history.

Pick-to: 6.9 6.8 6.5 5.15
Change-Id: Icd0eabc4129b57251bbec7f8e3752f99ee584cf3
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-03-27 13:02:35 +01:00
parent fbaa376335
commit f3a02fe39d

View File

@ -708,16 +708,16 @@ void tst_QGraphicsLayout::alternativeLayoutItems()
lout->setSpacing(0);
QGraphicsRectItem *item1 = new QGraphicsRectItem;
AnimatedLayoutItem *li1 = new AnimatedLayoutItem(item1);
lout->addItem(li1);
const auto li1 = std::make_unique<AnimatedLayoutItem>(item1);
lout->addItem(li1.get());
QGraphicsRectItem *item2 = new QGraphicsRectItem;
AnimatedLayoutItem *li2 = new AnimatedLayoutItem(item2);
lout->addItem(li2);
const auto li2 = std::make_unique<AnimatedLayoutItem>(item2);
lout->addItem(li2.get());
QGraphicsRectItem *item3 = new QGraphicsRectItem;
AnimatedLayoutItem *li3 = new AnimatedLayoutItem(item3);
lout->addItem(li3);
const auto li3 = std::make_unique<AnimatedLayoutItem>(item3);
lout->addItem(li3.get());
window->setLayout(lout);