From 1fdde67ff3ae6ec02a06b08ed82e8653f7b066a8 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Tue, 25 Apr 2017 14:58:35 +0200 Subject: QQmlApplicationEngine: Fix using invalid pointers When a root object was deleted before QQmlApplicationEngine the invalid pointers stayed in the list of root objects leading to crashes when destructing QQmlApplicationEngine. Root objects are watched for destruction and removed from the list. Change-Id: I1babab54dbb7d7b16ed883ada5b3e420ca8690cb Reviewed-by: Simon Hausmann --- .../tst_qqmlapplicationengine.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index f7748b2da9..daeb9b5455 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -28,6 +28,7 @@ #include "../../shared/util.h" #include +#include #include #if QT_CONFIG(process) #include @@ -47,6 +48,7 @@ private slots: void testNonResolvedPath(); void application(); void applicationProperties(); + void removeObjectsWhenDestroyed(); private: QString buildDir; QString srcDir; @@ -201,6 +203,23 @@ void tst_qqmlapplicationengine::applicationProperties() delete test; } +void tst_qqmlapplicationengine::removeObjectsWhenDestroyed() +{ + QScopedPointer test(new QQmlApplicationEngine); + QVERIFY(test->rootObjects().isEmpty()); + + QSignalSpy objectCreated(test.data(), SIGNAL(objectCreated(QObject*,QUrl))); + test->load(testFileUrl("basicTest.qml")); + QCOMPARE(objectCreated.count(), 1); + + QSignalSpy objectDestroyed(test->rootObjects().first(), SIGNAL(destroyed())); + test->rootObjects().first()->deleteLater(); + objectDestroyed.wait(); + QCOMPARE(objectDestroyed.count(), 1); + QCOMPARE(test->rootObjects().size(), 0); +} + + QTEST_MAIN(tst_qqmlapplicationengine) #include "tst_qqmlapplicationengine.moc" -- cgit v1.2.3