diff options
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/data/MyComponent.qml | 11 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/data/MyComponent2.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/data/MyComponent3.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/data/trim_cache2.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 14 |
6 files changed, 58 insertions, 2 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 01200fd881..6480420212 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1961,8 +1961,10 @@ void QQmlTypeLoader::trimCache() QList<TypeCache::Iterator> unneededTypes; for (TypeCache::Iterator iter = m_typeCache.begin(), end = m_typeCache.end(); iter != end; ++iter) { QQmlTypeData *typeData = iter.value(); - if (typeData->m_compiledData && typeData->count() == 1 - && typeData->m_compiledData->count() == 1) { + + const bool hasError = !typeData->m_compiledData && !typeData->m_errors.isEmpty(); + const bool isNotReferenced = typeData->m_compiledData && typeData->m_compiledData->count() == 1; + if (typeData->count() == 1 && (hasError || isNotReferenced)) { // There are no live objects of this type unneededTypes.append(iter); } diff --git a/tests/auto/qml/qqmltypeloader/data/MyComponent.qml b/tests/auto/qml/qqmltypeloader/data/MyComponent.qml new file mode 100644 index 0000000000..a642518199 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/MyComponent.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 62 + + MyComponent3 {} + + MyComponent2 {} +} + diff --git a/tests/auto/qml/qqmltypeloader/data/MyComponent2.qml b/tests/auto/qml/qqmltypeloader/data/MyComponent2.qml new file mode 100644 index 0000000000..02cf5cb5dd --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/MyComponent2.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 62 +} + diff --git a/tests/auto/qml/qqmltypeloader/data/MyComponent3.qml b/tests/auto/qml/qqmltypeloader/data/MyComponent3.qml new file mode 100644 index 0000000000..ad5d569197 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/MyComponent3.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 62 + + MyComponent4 {} +} + diff --git a/tests/auto/qml/qqmltypeloader/data/trim_cache2.qml b/tests/auto/qml/qqmltypeloader/data/trim_cache2.qml new file mode 100644 index 0000000000..326a720a87 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/trim_cache2.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + width: 400 + height: 400 + + Component.onCompleted: { + var component = Qt.createComponent("MyComponent.qml") + if (component.status == Component.Error) + console.log(component.errorString()) + } +} + diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index a1eaa0567f..8eb413e9f7 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -48,6 +48,7 @@ private slots: void testLoadComplete(); void loadComponentSynchronously(); void trimCache(); + void trimCache2(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -112,6 +113,19 @@ void tst_QQMLTypeLoader::trimCache() } } +void tst_QQMLTypeLoader::trimCache2() +{ + QQuickView *window = new QQuickView(); + window->setSource(testFileUrl("trim_cache2.qml")); + QQmlTypeLoader &loader = QQmlEnginePrivate::get(window->engine())->typeLoader; + // in theory if gc has already run this could be false + // QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), true); + window->engine()->collectGarbage(); + QTest::qWait(1); // force event loop + window->engine()->trimComponentCache(); + QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), false); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |