aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp1
-rw-r--r--tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml9
-rw-r--r--tests/auto/qml/qqmltypeloader/data/trim_cache3.qml14
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp21
4 files changed, 44 insertions, 1 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 9dd82494ca..2f8a70d63b 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -1969,7 +1969,6 @@ void QQmlDelegateModelItem::incubateObject(
QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
incubatorPriv->compilationUnit = componentPriv->compilationUnit;
- incubatorPriv->compilationUnit->addref();
incubatorPriv->enginePriv = enginePriv;
incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext));
incubatorPriv->subComponentToCreate = componentPriv->start;
diff --git a/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml b/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml
new file mode 100644
index 0000000000..b3610831df
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+
+Item {
+ Repeater {
+ model: 3
+ Item {}
+ }
+}
+
diff --git a/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml b/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml
new file mode 100644
index 0000000000..219c7d3bcb
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Item {
+ width: 400
+ height: 400
+
+ property alias source: loader.source
+
+ Loader {
+ id: loader
+ source: "ComponentWithIncubator.qml"
+ }
+}
+
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index 5ab729042f..5a3d76e903 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -44,6 +44,7 @@ private slots:
void loadComponentSynchronously();
void trimCache();
void trimCache2();
+ void trimCache3();
void keepSingleton();
void keepRegistrations();
void intercept();
@@ -124,6 +125,26 @@ void tst_QQMLTypeLoader::trimCache2()
QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), false);
}
+// test trimming the cache of an item that contains sub-items created via incubation
+void tst_QQMLTypeLoader::trimCache3()
+{
+ QScopedPointer<QQuickView> window(new QQuickView());
+ window->setSource(testFileUrl("trim_cache3.qml"));
+ QQmlTypeLoader &loader = QQmlEnginePrivate::get(window->engine())->typeLoader;
+ QCOMPARE(loader.isTypeLoaded(testFileUrl("ComponentWithIncubator.qml")), true);
+
+ QQmlProperty::write(window->rootObject(), "source", QString());
+
+ // handle our deleteLater and cleanup
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+ window->engine()->collectGarbage();
+
+ window->engine()->trimComponentCache();
+
+ QCOMPARE(loader.isTypeLoaded(testFileUrl("ComponentWithIncubator.qml")), false);
+}
+
static void checkSingleton(const QString &dataDirectory)
{
QQmlEngine engine;