aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-01-14 11:42:20 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-01-15 13:10:22 +0000
commitae8fb3800ac880bfa9805f9163709d96b66b7788 (patch)
tree8d03a88eea6fd74f69c47566cd95d559bddf2144 /tests
parent0b5ae19f733c7d59e6138c677fe432a0e6f25938 (diff)
QQmlComponent: Avoid crash when setting initial properties in JS module
In a JS module, we lack a qml context. Thus, we have to check whether qmlContext is null. In that case we use the engine's scriptContext('s ExecutionContext) instead. Fixes: QTBUG-90245 Change-Id: I337e9c7cade472f52fc81c93d1152ff59f8018a5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit e68b498424f63c1cb6151e4fc6bbc50bac584909)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml5
-rw-r--r--tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs6
-rw-r--r--tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml10
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp10
4 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml b/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml
new file mode 100644
index 0000000000..0d894eb3fe
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ property int value
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs b/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs
new file mode 100644
index 0000000000..3dd3507d45
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs
@@ -0,0 +1,6 @@
+export function withProp(root) {
+ const component = Qt.createComponent("data/jsmodule/Dynamic.qml");
+ const el = component.createObject(root, { value: 42 });
+ return el.value;
+}
+
diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml b/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml
new file mode 100644
index 0000000000..123c857180
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml
@@ -0,0 +1,10 @@
+import "./module.mjs" as MJ
+import QtQml 2.15
+
+QtObject {
+ id: root
+ property bool ok: false
+ Component.onCompleted: {
+ root.ok = MJ.withProp(root) == 42
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index 36c13bb705..c4a1a6aea4 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -125,6 +125,7 @@ private slots:
void testRequiredProperties();
void testRequiredPropertiesFromQml();
void testSetInitialProperties();
+ void createInsideJSModule();
private:
QQmlEngine engine;
@@ -832,6 +833,15 @@ void tst_qqmlcomponent::testSetInitialProperties()
}
}
+void tst_qqmlcomponent::createInsideJSModule()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("jsmodule/test.qml"));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
+ QVERIFY(root->property("ok").toBool());
+}
+
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"