aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-03-31 16:28:24 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2022-11-28 17:10:07 +0100
commit6656567a4085e3d6de01226fb7b1ec16ee7ba08c (patch)
tree9d021e9f3c17d468dcc6bc1be52c0e595019a662 /tests/auto/qml/qqmlecmascript
parent6cd8d209ec472a658a330f25b84f92cd61e0d4cf (diff)
Introduce type based overload of Qt.createComponent
Add type based createComponent overloads based on QQmlComponent::loadFromModule. They provide a way to instantiate a component by its type, specified by a URI and typename pair. This enables creating Components for inline component types and C++ only types. Support for directly passing the type is deferred to a later commit, as it needs some care to work together with the compiler. As the string based overload matches a mistaken call to the URL based createComponent with parent and mode swapped (due to anything being convertible to string), we add a check to detect this specific error case and give a helpful error message. [ChangeLog][QtQml] Qt.createComponent now supports creating a Component from its module and type name (passed as strings). Task-number: QTBUG-97156 Fixes: QTBUG-26278 Change-Id: I89e7430fe02d52f57230bfa1b0bfbcbfd0ead4b7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/componentCreationForType.qml48
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp4
2 files changed, 50 insertions, 2 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/componentCreationForType.qml b/tests/auto/qml/qqmlecmascript/data/componentCreationForType.qml
new file mode 100644
index 0000000000..66b06d4f5c
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/componentCreationForType.qml
@@ -0,0 +1,48 @@
+import QtQml
+
+QtObject {
+ id: root
+ property int status: -1
+ Component.onCompleted: {
+ let comp
+ comp = Qt.createComponent("QtQml", "QtObject")
+ if (comp.status !== Component.Ready) {
+ root.status = 1
+ return
+ }
+
+ comp = Qt.createComponent("QtQml", "QtObject", root)
+ if (comp.status !== Component.Ready) {
+ root.status = 2
+ return
+ }
+
+ comp = Qt.createComponent("QtQml", "QtObject", Component.PreferSynchronous, root)
+ if (comp.status !== Component.Ready) {
+ root.status = 3
+ return
+ }
+
+
+ comp = Qt.createComponent("QtQml", "QtObject", Component.Asynchronous)
+ // C++ component will _always_ be ready, even if we request async loading
+ if (comp.status !== Component.Ready) {
+ root.status = 4
+ return
+ }
+
+ comp = Qt.createComponent("QtQml", "DoesNotExist")
+ if (comp.status !== Component.Error) {
+ root.status = 5
+ return
+ }
+
+ comp = Qt.createComponent("NoSuchModule", "QtObject")
+ if (comp.status !== Component.Error) {
+ root.status = 6
+ return
+ }
+
+ root.status = 0
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 2922b02643..f591a87dcb 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -1964,11 +1964,11 @@ void tst_qqmlecmascript::componentCreation_data()
<< "null";
QTest::newRow("invalidSecondArg")
<< "invalidSecondArg"
- << "" // We cannot catch this case as coercing a string to a number is valid in JavaScript
+ << ":40: TypeError: Invalid arguments; did you swap mode and parent"
<< "";
QTest::newRow("invalidThirdArg")
<< "invalidThirdArg"
- << ":45: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed."
+ << ":45: TypeError: Invalid arguments; did you swap mode and parent"
<< "";
QTest::newRow("invalidMode")
<< "invalidMode"