From 364f6c200a6faac825c7f1e0158d708fc60a8ff5 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 24 Mar 2010 12:42:04 +1000 Subject: Fix Loader leak when loading a non-QGraphicsObject object. --- src/declarative/graphicsitems/qdeclarativeloader.cpp | 6 +++++- tests/auto/declarative/qdeclarativeloader/data/nonItem.qml | 5 +++++ .../qdeclarativeloader/tst_qdeclarativeloader.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeloader/data/nonItem.qml diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 544e9ec..4301467 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -303,9 +303,9 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() return; } if (obj) { - QDeclarative_setParent_noEvent(ctxt, obj); item = qobject_cast(obj); if (item) { + QDeclarative_setParent_noEvent(ctxt, obj); if (QDeclarativeItem* qmlItem = qobject_cast(item)) { qmlItem->setParentItem(q); } else { @@ -314,6 +314,10 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() } // item->setFocus(true); initResize(); + } else { + qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements."); + delete obj; + delete ctxt; } } else { delete obj; diff --git a/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml b/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml new file mode 100644 index 0000000..f42c1d5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeloader/data/nonItem.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Loader { + sourceComponent: QtObject {} +} diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index f27c1ce..7123dda 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -91,6 +91,7 @@ private slots: // void networkComponent(); void deleteComponentCrash(); + void nonItem(); private: QDeclarativeEngine engine; @@ -485,6 +486,18 @@ void tst_QDeclarativeLoader::deleteComponentCrash() delete item; } +void tst_QDeclarativeLoader::nonItem() +{ + QSKIP("QTBUG-9245", SkipAll); + QDeclarativeComponent component(&engine, TEST_FILE("/nonItem.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML Loader (file://" SRCDIR "/data/nonItem.qml:3:1) Loader does not support loading non-visual elements."); + QDeclarativeLoader *loader = qobject_cast(component.create()); + QVERIFY(loader); + QVERIFY(loader->item() == 0); + + delete loader; +} + void tst_QDeclarativeLoader::networkSafety_data() { QTest::addColumn("url"); -- cgit v0.12