From b4d36a05be9f34976c1a1b5ea60ce03c4ab59a25 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 15 Jul 2020 10:42:48 +0200 Subject: QQmlIRLoader: Restore inline components correctly Whether a component is an inline component is not only stored in the flags, but also in the isInlineComponent member. Ideally, this should be unified and the member removed, but for now we just restore the value correctly. Adjusted tst_qmlcachegen::initTestCase so that we testFile and testFileUrl are actually usable in the test. Fixes: QTBUG-84237 Pick-to: 5.15 Change-Id: I759cd6b8914b186b9e5c8118863fc8d0580d21af Reviewed-by: Mitch Curtis --- src/qml/qml/qqmlirloader.cpp | 1 + tests/auto/qml/qmlcachegen/data/inlineComponentWithId.qml | 10 ++++++++++ tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/auto/qml/qmlcachegen/data/inlineComponentWithId.qml diff --git a/src/qml/qml/qqmlirloader.cpp b/src/qml/qml/qqmlirloader.cpp index a0ae923bac..fc1a3f9d91 100644 --- a/src/qml/qml/qqmlirloader.cpp +++ b/src/qml/qml/qqmlirloader.cpp @@ -95,6 +95,7 @@ QmlIR::Object *QQmlIRLoader::loadObject(const QV4::CompiledData::Object *seriali object->indexOfDefaultPropertyOrAlias = serializedObject->indexOfDefaultPropertyOrAlias; object->defaultPropertyIsAlias = serializedObject->defaultPropertyIsAlias; + object->isInlineComponent = serializedObject->flags & QV4::CompiledData::Object::IsInlineComponentRoot; object->flags = serializedObject->flags; object->id = serializedObject->id; object->location = serializedObject->location; diff --git a/tests/auto/qml/qmlcachegen/data/inlineComponentWithId.qml b/tests/auto/qml/qmlcachegen/data/inlineComponentWithId.qml new file mode 100644 index 0000000000..ef9a157e5e --- /dev/null +++ b/tests/auto/qml/qmlcachegen/data/inlineComponentWithId.qml @@ -0,0 +1,10 @@ +import QtQuick 2.15 + +Item { + component Test: Item { + id: test + property int t: 42 + Component.onCompleted: console.info(test.t) + } + Test {} +} diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 652942b243..283aef9317 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -76,6 +76,7 @@ private slots: void reproducibleCache(); void parameterAdjustment(); + void inlineComponent(); }; // A wrapper around QQmlComponent to ensure the temporary reference counts @@ -129,6 +130,7 @@ void tst_qmlcachegen::initTestCase() if (!cacheDir.isEmpty()) //QDir(cacheDir).removeRecursively(); qDebug() << cacheDir; + QQmlDataTest::initTestCase(); } void tst_qmlcachegen::loadGeneratedFile() @@ -690,6 +692,18 @@ void tst_qmlcachegen::parameterAdjustment() QVERIFY(!obj.isNull()); // Doesn't crash } + +void tst_qmlcachegen::inlineComponent() +{ + bool ok = generateCache(testFile("inlineComponentWithId.qml")); + QVERIFY(ok); + QQmlEngine engine; + CleanlyLoadingComponent component(&engine, testFileUrl("inlineComponentWithId.qml")); + QTest::ignoreMessage(QtMsgType::QtInfoMsg, "42"); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); +} + QTEST_GUILESS_MAIN(tst_qmlcachegen) #include "tst_qmlcachegen.moc" -- cgit v1.2.3