tst_QGraphicsScene: fix memleak in taskQTBUG_5904_crashWithDeviceCoordinateCache()

The test had it the wrong way around: it deleted the QWidget it had
added to the QGraphicsScene, which thus becomes the widget's owner,
but left the scene itself undeleted, leaking it and all the items (but
not the widget ;-)).

Create the scene on the stack, so it's deleted by the compiler, and
release() the widget into the scene.addWidget() call. Since
QScopedPointer::take() is deprecated, port to std::unique_ptr.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Idbf821a35a7db802a68923fc09b185ddc3181245
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit fdcf54062cfd372d528948da4637b98b403e174e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-24 15:55:47 +01:00 committed by Qt Cherry-pick Bot
parent b859f192e9
commit 081023ec0e

View File

@ -4401,17 +4401,17 @@ void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache()
void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts()
{
// Test using DeviceCoordinateCache and opaque item
QScopedPointer<QWidget> w(new QWidget);
auto w = std::make_unique<QWidget>();
w->setPalette(QColor(0, 0, 255));
w->setGeometry(0, 0, 50, 50);
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsScene scene;
CustomView view;
view.resize(m_testSize);
view.setWindowTitle(QTest::currentTestFunction());
view.setScene(scene);
view.setScene(&scene);
QGraphicsProxyWidget *proxy = scene->addWidget(w.data());
QGraphicsProxyWidget *proxy = scene.addWidget(w.release());
proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
proxy->setTransform(QTransform().rotate(15), true);