aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-07-03 15:13:46 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-07-09 16:52:55 +0200
commit910f98031fdd834a22af0da21c9ff6ae145f61c5 (patch)
tree03062e2ec8ccca2a1bbdc2c6e69587de1eedbe76 /tests
parentf2cb10ebc4946b10526fa22581913ccc04cea164 (diff)
Add support for C++ accessible typed parameters and return types in qml functions
These can be declared using the new typescript-like syntax and using type names that are also used for signal parameters and property types. This merely affects their signature on the C++ side and allows the corresponding invocation. Change-Id: Icaed4ee0dc7aa71330f99d96e073a2a63d409bbe Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/data/typeAnnotations.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/typeAnnotations.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp27
6 files changed, 32 insertions, 18 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml b/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml
new file mode 100644
index 0000000000..26931a4f10
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0 as QQ
+import QtQml 2.0 as Core
+QQ.Item {
+ id: root
+ function returnItem() : Core.QtObject { return root; }
+ function takeString(arg: string) { return arg; }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt
deleted file mode 100644
index 141ea9c7bc..0000000000
--- a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt
+++ /dev/null
@@ -1 +0,0 @@
-4:26:Type annotations are not supported (yet).
diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml
deleted file mode 100644
index 03272e9d50..0000000000
--- a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml
+++ /dev/null
@@ -1,7 +0,0 @@
-import QtQml 2.0
-
-QtObject {
- function notYet(param: string) {
- return param
- }
-}
diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.errors.txt b/tests/auto/qml/qqmllanguage/data/typeAnnotations.errors.txt
deleted file mode 100644
index 3db89a47d5..0000000000
--- a/tests/auto/qml/qqmllanguage/data/typeAnnotations.errors.txt
+++ /dev/null
@@ -1 +0,0 @@
-4:5:Type annotations are not supported (yet).
diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.qml b/tests/auto/qml/qqmllanguage/data/typeAnnotations.qml
deleted file mode 100644
index d8cc4535eb..0000000000
--- a/tests/auto/qml/qqmllanguage/data/typeAnnotations.qml
+++ /dev/null
@@ -1,7 +0,0 @@
-import QtQml 2.0
-
-QtObject {
- function notYet() : string {
- return "ko"
- }
-}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index ac7874b701..11e46beb41 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -208,6 +208,7 @@ private slots:
void remoteLoadCrash();
void signalWithDefaultArg();
void signalParameterTypes();
+ void functionParameterTypes();
// regression tests for crashes
void crash1();
@@ -623,9 +624,7 @@ void tst_qqmllanguage::errors_data()
QTest::newRow("bareQmlImport") << "bareQmlImport.qml" << "bareQmlImport.errors.txt" << false;
- QTest::newRow("typeAnnotations") << "typeAnnotations.qml" << "typeAnnotations.errors.txt" << false;
QTest::newRow("typeAnnotations.2") << "typeAnnotations.2.qml" << "typeAnnotations.2.errors.txt" << false;
- QTest::newRow("typeAnnotations.3") << "typeAnnotations.3.qml" << "typeAnnotations.3.errors.txt" << false;
}
@@ -3702,6 +3701,30 @@ void tst_qqmllanguage::signalParameterTypes()
}
}
+void tst_qqmllanguage::functionParameterTypes()
+{
+ QQmlComponent component(&engine, testFileUrl("functionParameterTypes.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(!obj.isNull(), qPrintable(component.errorString()));
+ const QMetaObject *metaObject = obj->metaObject();
+
+ {
+ QMetaMethod slot = metaObject->method(metaObject->indexOfSlot("returnItem()"));
+ QVERIFY(slot.isValid());
+ QCOMPARE(slot.returnType(), QMetaType::type("QObject*"));
+ QObject *returnedPtr = nullptr;
+ slot.invoke(obj.data(), Qt::DirectConnection, Q_RETURN_ARG(QObject*, returnedPtr));
+ QCOMPARE(returnedPtr, obj.data());
+ }
+
+ {
+ QMetaMethod slot = metaObject->method(metaObject->indexOfSlot("takeString(QString)"));
+ QVERIFY(slot.isValid());
+ QCOMPARE(slot.parameterCount(), 1);
+ QCOMPARE(slot.parameterType(0), int(QMetaType::QString));
+ }
+}
+
// QTBUG-20639
void tst_qqmllanguage::globalEnums()
{