aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-22 13:40:09 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-02-23 12:09:42 +0100
commitc8e756e560ce3f0d369df65986e5578e0e963c66 (patch)
treefcb2a9491e884103ecea358747ecb6045b2ca00a /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent6b5aa145969a30a98cba53ad8b8e5bd5e92aa154 (diff)
QML: Take care of QVariant when converting function arguments
We cannot convert to QVariant using QMetaType::convert(). But we can just construct a QVariant with the desired type and data. This will become an issue once we automatically convert argument types to match the desired type inside the function. As a side effect, also allow declaring "var" arguments to functions. Change-Id: Idc14021d8d85d3d09ee7b7f286de91b56ea02bfd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 46e0b4fb90..bad7271d5a 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -23,6 +23,8 @@
#include <data/cppbaseclass.h>
#include <data/objectwithmethod.h>
+#include <QtQml/private/qqmlengine_p.h>
+
#include <QtTest>
#include <QtQml>
#include <QtGui/qcolor.h>
@@ -121,6 +123,7 @@ private slots:
void blockComments();
void functionLookup();
void objectInVar();
+ void functionTakingVar();
};
void tst_QmlCppCodegen::simpleBinding()
@@ -1824,6 +1827,26 @@ void tst_QmlCppCodegen::objectInVar()
QVERIFY(!result);
}
+void tst_QmlCppCodegen::functionTakingVar()
+{
+ QQmlEngine engine;
+ const QUrl document(u"qrc:/TestTypes/functionTakingVar.qml"_qs);
+ QQmlComponent c(&engine, document);
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+
+ QVERIFY(!o->property("c").isValid());
+
+ int value = 11;
+ QQmlEnginePrivate *e = QQmlEnginePrivate::get(&engine);
+ void *args[] = { nullptr, reinterpret_cast<void *>(std::addressof(value)) };
+ QMetaType types[] = { QMetaType::fromType<void>(), QMetaType::fromType<std::decay_t<int>>() };
+ e->executeRuntimeFunction(document, 0, o.data(), 1, args, types);
+
+ QCOMPARE(o->property("c"), QVariant::fromValue<int>(11));
+}
+
void tst_QmlCppCodegen::runInterpreted()
{
if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER"))