diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2026-02-23 14:39:00 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2026-02-25 17:41:35 +0100 |
| commit | 441e111330be2b4aec12f42b41e449ecb5f8a02c (patch) | |
| tree | cf4c145f81fca965569137ac3d3bd8df33f605ae | |
| parent | 391dc10ad5bbf92f0335b603b1125f948616086d (diff) | |
QtQml: Don't invalidate cache files for self-referencing signals
We need to store the QML type early so that it is seen as resolved.
Pick-to: 6.8
Change-Id: I3df3d3dca4e84e350973dc31ad48f33ac32d6168
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 05dfaf3cac3fd45f5e2461b6a2532a57b5351389)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 8f092cb5e92ef1df476c860421f056cf70f6f1f3)
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
| -rw-r--r-- | src/qml/qml/qqmltypedata.cpp | 1 | ||||
| -rw-r--r-- | tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index 773d7d9fc2..c3a65857a5 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -340,6 +340,7 @@ QQmlError QQmlTypeData::createTypeAndPropertyCaches( m_compiledData->typeNameCache = typeNameCache; m_compiledData->resolvedTypes = resolvedTypeCache; m_compiledData->inlineComponentData = m_inlineComponentData; + m_compiledData->qmlType = m_qmlType; QQmlPendingGroupPropertyBindings pendingGroupPropertyBindings; diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 4301ac96fc..bd5ff05af8 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -46,6 +46,7 @@ private slots: void inlineComponentDoesNotCauseConstantInvalidation_data(); void inlineComponentDoesNotCauseConstantInvalidation(); + void selfReferencingSignalParameter(); void selfReferenceDoesNotInvalidateCache(); @@ -1421,6 +1422,64 @@ void tst_qmldiskcache::selfReferenceDoesNotInvalidateCache() } } +void tst_qmldiskcache::selfReferencingSignalParameter() +{ + QQmlEngine engine; + + QTemporaryDir tempDir; + QVERIFY(tempDir.isValid()); + + // Write a QML file that uses itself as a signal parameter type + const QString testFilePath = tempDir.path() + "/SelfReference.qml"; + { + QFile f(testFilePath); + QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString())); + f.write(QByteArrayLiteral("import QtQml\n" + "QtObject {\n" + " property SelfReference self\n" + " signal blah(selfParam: SelfReference)\n" + " function returnSelf() : SelfReference { return this; }\n" + "}")); + } + + const QString mainFilePath = tempDir.path() + "/main.qml"; + { + QFile f(mainFilePath); + QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString())); + f.write(QByteArrayLiteral("import QtQml\nSelfReference {}")); + } + + // First load: compiles and creates cache + { + CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(mainFilePath)); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + } + + const QString cacheFilePath = QV4::CompiledData::CompilationUnit::localCacheFilePath( + QUrl::fromLocalFile(testFilePath)); + QVERIFY(QFile::exists(cacheFilePath)); + QDateTime initialCacheTimeStamp = QFileInfo(cacheFilePath).lastModified(); + + engine.clearComponentCache(); + waitForFileSystem(); + + // Second load: should use the cache without invalidation + { + CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(mainFilePath)); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + } + + { + QVERIFY(QFile::exists(cacheFilePath)); + QDateTime newCacheTimeStamp = QFileInfo(cacheFilePath).lastModified(); + QCOMPARE(newCacheTimeStamp, initialCacheTimeStamp); + } +} + QTEST_MAIN(tst_qmldiskcache) #include "tst_qmldiskcache.moc" |
