summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-02-02 14:24:40 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-03 13:14:30 +0000
commit7f99a69e25ee3ae99c3b4ba713b8c6b5e8e60135 (patch)
tree1991cbc25c77146e98560d30f2053c5ec095ebe3
parent587662a74088bafa56ba4cf551d1e92f54200d21 (diff)
QQmlIRLoader: Actually load RequiredPropertyExtraData
If a QML component wants to mark properties of its "parent" component as required, it can do so via required propertyName The information about those properties is stored in a RequiredPropertyExtraData data structure. This structure is already serialized to disk in the QQmlIRWriter. However, we neglected to restore it so far in the loader. Fixes: QTBUG-90538 Change-Id: I789daff9bc881e4f35c942c77f5116b5284de81b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit b322a971f06823a4356f2b3aa331501aa4d0dc7f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/qml/qqmlirloader.cpp7
-rw-r--r--tests/auto/qml/qmlcachegen/data/posthocrequired.qml5
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp12
3 files changed, 24 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlirloader.cpp b/src/qml/qml/qqmlirloader.cpp
index 121ac25ced..6f763707d1 100644
--- a/src/qml/qml/qqmlirloader.cpp
+++ b/src/qml/qml/qqmlirloader.cpp
@@ -208,6 +208,13 @@ QmlIR::Object *QQmlIRLoader::loadObject(const QV4::CompiledData::Object *seriali
object->inlineComponents->append(ic);
}
+ const QV4::CompiledData::RequiredPropertyExtraData *serializedRequiredPropertyExtraData = serializedObject->requiredPropertyExtraDataTable();
+ for (uint i = 0u; i < serializedObject->nRequiredPropertyExtraData; ++i, ++serializedRequiredPropertyExtraData) {
+ QmlIR::RequiredPropertyExtraData *extra = pool->New<QmlIR::RequiredPropertyExtraData>();
+ *static_cast<QV4::CompiledData::RequiredPropertyExtraData *>(extra) = *serializedRequiredPropertyExtraData;
+ object->requiredPropertyExtraDatas->append(extra);
+ }
+
return object;
}
diff --git a/tests/auto/qml/qmlcachegen/data/posthocrequired.qml b/tests/auto/qml/qmlcachegen/data/posthocrequired.qml
new file mode 100644
index 0000000000..3b32d9fe8f
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/data/posthocrequired.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.15
+
+Item {
+ required x
+}
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index bc6451dac0..b999b5b9d1 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -77,6 +77,7 @@ private slots:
void parameterAdjustment();
void inlineComponent();
+ void posthocRequired();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -704,6 +705,17 @@ void tst_qmlcachegen::inlineComponent()
QVERIFY(!obj.isNull());
}
+void tst_qmlcachegen::posthocRequired()
+{
+ bool ok = generateCache(testFile("posthocrequired.qml"));
+ QVERIFY(ok);
+ QQmlEngine engine;
+ CleanlyLoadingComponent component(&engine, testFileUrl("posthocrequired.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(obj.isNull() && component.isError());
+ QVERIFY(component.errorString().contains(QStringLiteral("Required property x was not initialized")));
+}
+
QTEST_GUILESS_MAIN(tst_qmlcachegen)
#include "tst_qmlcachegen.moc"