aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2024-05-14 14:04:56 +0200
committerLuca Di Sera <luca.disera@qt.io>2024-05-22 18:02:37 +0200
commit9c113e8ec6350d06ef265511b821a42f0d8eb77c (patch)
treea7706dffaa0f4b0ea2f2f28e841c87ea64469415
parent8dbcea319a20b0bc905d2988dc9f35394f73c2dc (diff)
Add a wrapper builtin for QJsonArray
Calling `qmllint` can produce warning for usages of the `QJsonArray` type, due to it not being found. Nonetheless, the engine special handles the type, so that `qmllint` should not warn about it. Make `QJsonArray` a builtin type so that calls to `qmllint` will import and recognize the type. Add a test-case to ensure that the type is now recognized. Task-number: QTBUG-111015 Change-Id: I51744968a0316ccb016a4404326b74fa419037bd Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/qqmlbuiltins_p.h18
-rw-r--r--tests/auto/qml/qmllint/data/Qtbug111015/qtbug111015.qmltypes8
-rw-r--r--tests/auto/qml/qmllint/data/jsonArrayIsRecognized.qml8
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
4 files changed, 35 insertions, 0 deletions
diff --git a/src/qml/qqmlbuiltins_p.h b/src/qml/qqmlbuiltins_p.h
index 43e3a70dff..d95ed26ab6 100644
--- a/src/qml/qqmlbuiltins_p.h
+++ b/src/qml/qqmlbuiltins_p.h
@@ -36,6 +36,8 @@
#include <QtCore/qtypes.h>
#include <QtCore/qchar.h>
#include <QtCore/qjsonobject.h>
+#include <QtCore/qjsonvalue.h>
+#include <QtCore/qjsonarray.h>
#include <climits>
@@ -410,6 +412,22 @@ struct QQmlQJsonObjectForeign
QML_EXTENDED_JAVASCRIPT(Object)
};
+struct QQmlQJsonValueForeign
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(QJsonValue)
+ QML_EXTENDED_JAVASCRIPT(Object)
+};
+
+struct QQmlQJsonArrayForeign
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(QJsonArray)
+ QML_SEQUENTIAL_CONTAINER(QJsonValue)
+};
+
QT_END_NAMESPACE
#endif // QQMLBUILTINS_H
diff --git a/tests/auto/qml/qmllint/data/Qtbug111015/qtbug111015.qmltypes b/tests/auto/qml/qmllint/data/Qtbug111015/qtbug111015.qmltypes
index cad6d88cc3..7de521a379 100644
--- a/tests/auto/qml/qmllint/data/Qtbug111015/qtbug111015.qmltypes
+++ b/tests/auto/qml/qmllint/data/Qtbug111015/qtbug111015.qmltypes
@@ -9,4 +9,12 @@ Module {
prototype: "QObject"
Property { name: "jsonObjectList"; type: "QJsonObject"; isList: true; read: "getJsonObjectList"; index: 0; isReadonly: true }
}
+ Component {
+ file: "typewithjsonarray.h"
+ name: "TypeWithJsonArray"
+ exports: ["QmlLintTestLib/TypeWithJsonArray 1.0"]
+ accessSemantics: "reference"
+ prototype: "QObject"
+ Property { name: "jsonArray"; type: "QJsonArray"; read: "getJsonArray"; index: 0; isReadonly: true }
+ }
}
diff --git a/tests/auto/qml/qmllint/data/jsonArrayIsRecognized.qml b/tests/auto/qml/qmllint/data/jsonArrayIsRecognized.qml
new file mode 100644
index 0000000000..89c52e0e52
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/jsonArrayIsRecognized.qml
@@ -0,0 +1,8 @@
+import QtQuick
+import Qtbug111015 1.0
+
+Item {
+ TypeWithJsonArray {
+ jsonArray: []
+ }
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index bcccd5f1f0..1ae90d62c7 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -1348,6 +1348,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("constInvokable") << QStringLiteral("useConstInvokable.qml");
QTest::newRow("dontCheckJSTypes") << QStringLiteral("dontCheckJSTypes.qml");
QTest::newRow("jsonObjectIsRecognized") << QStringLiteral("jsonObjectIsRecognized.qml");
+ QTest::newRow("jsonArrayIsRecognized") << QStringLiteral("jsonArrayIsRecognized.qml");
}
void TestQmllint::cleanQmlCode()