From d9d1c1fb5e324ce379bac4087178e63adc0c58ba Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 6 Feb 2025 17:29:09 +0100 Subject: QtQml: Support url and date in 'instanceof' and 'as' Those have several possible representations. Besides QQmlValueTypeWrapper, they can also be their own special heap objects with extra methods, or VariantObject. Also, remove some pointless restrictions in QmlCompiler that prevented such as-casts from being compiled to C++. The code generator will currently reject non-trivial type assertions for value types. Therefore we don't have to take care of ValueTypeBehavior: Assertable, yet. Also fix tst_qqmllanguage::instanceOf() to actually test something. So far the return value of the expression was ignored for most data tags. Pick-to: 6.9 Fixes: QTBUG-130291 Change-Id: I2facf48455a04a02a078615e5ebd4b1c26d1bd93 Reviewed-by: Sami Shalayel --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index d3f917e280..e023d705d9 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -738,6 +738,10 @@ void tst_QmlCppCodegen::asCast() QCOMPARE(qvariant_cast(root->property("undefinedAsItem")), nullptr); QCOMPARE(qvariant_cast(root->property("undefinedAsRectangle")), nullptr); QCOMPARE(qvariant_cast(root->property("undefinedAsDummy")), nullptr); + + QCOMPARE(root->property("stringAsString"), u"a"_s); + QCOMPARE(root->property("urlAsUrl"), QUrl(u"http://example.com"_s)); + QCOMPARE(root->property("dateAsDate"), QDateTime(QDate(1996, 3, 3), QTime())); } void tst_QmlCppCodegen::attachedBaseEnum() -- cgit v1.2.3