From c327c43be82c6a2827df1f493ca4e3487a0fc9c3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 3 Jan 2019 10:36:44 +0100 Subject: Tests: Don't capture stack value by reference We can actually not capture d at all there, as some of the items get deleted before the root object is deleted. Therefore, we need to iterate the children again on receiving the destroyed() signal. Change-Id: Iab7ebc3c731438a21b243284de7515530232828f Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index 89640bc385..cb4bee0d3a 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -883,13 +883,13 @@ void tst_qqmlcontext::contextObjectHierarchy() QScopedPointer root(component.create()); QVERIFY(!root.isNull()); - for (const QObject *child : root->children()) { - QQmlData *d = QQmlData::get(child); - QVERIFY(d->outerContext != nullptr); - connect(root.data(), &QObject::destroyed, [&]() { - QCOMPARE(d->outerContext, nullptr); - }); - } + for (const QObject *child : root->children()) + QVERIFY(QQmlData::get(child)->outerContext != nullptr); + + connect(root.data(), &QObject::destroyed, [&root]() { + for (const QObject *child : root->children()) + QCOMPARE(QQmlData::get(child)->outerContext, nullptr); + }); } QTEST_MAIN(tst_qqmlcontext) -- cgit v1.2.3