aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-06-30 10:14:17 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-07-06 21:29:39 +0200
commitca27c051ab52b764df8c8aab9c33211cbf94eba1 (patch)
treef2215f58c940585ffa7dc00d11e4a61dc458711b /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent984f774ca9949c096bc3b9d04122c6c5014750a4 (diff)
QmlCompiler: Allow creation of structured value types
With this change, qmlcachegen can populate structured value types from object literals. Also fix the construction of value types via Q_INVOKABLE ctors. We don't need to wrap the ctor argument in QVariant if we can store the original type, and we should always look at the base type for the creatable flag, not the extension. Task-number: QTBUG-107469 Task-number: QTBUG-112485 Change-Id: I9f3db13f00466dc9d87237bdf0b380d6eeb58a10 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> 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.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index f4e8d31f5a..841f91995c 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -1,12 +1,13 @@
// Copyright (C) 2021 The Qt Company Ltd.
-#include "data/druggeljug.h"
-#include "data/enumProperty.h"
-#include "data/withlength.h"
#include <data/birthdayparty.h>
#include <data/cppbaseclass.h>
+#include <data/druggeljug.h>
+#include <data/enumProperty.h>
#include <data/enumproblems.h>
#include <data/objectwithmethod.h>
+#include <data/weathermoduleurl.h>
+#include <data/withlength.h>
#include <QtQml/private/qqmlengine_p.h>
#include <QtQml/private/qqmlpropertycachecreator_p.h>
@@ -171,6 +172,7 @@ private slots:
void stringArg();
void stringLength();
void stringToByteArray();
+ void structuredValueType();
void testIsnan();
void thisObject();
void throwObjectName();
@@ -3545,6 +3547,23 @@ void tst_QmlCppCodegen::stringToByteArray()
QCOMPARE(person->name(), u"some data"_s);
}
+void tst_QmlCppCodegen::structuredValueType()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/structuredValueType.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QCOMPARE(o->property("r").value<QRectF>(), QRectF(1, 2, 3, 4));
+ QCOMPARE(o->property("r2").value<QRectF>(), QRectF(42, 0, 0, 0));
+
+ WeatherModelUrl w;
+ w.setStrings(QStringList({"one", "two", "three"}));
+
+ QCOMPARE(o->property("w").value<WeatherModelUrl>(), w);
+}
+
void tst_QmlCppCodegen::testIsnan()
{
QQmlEngine engine;