From 6ff6c088c22938fc35690d385a9625f33c18a35a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 19 May 2022 16:38:55 +0200 Subject: QmlCompiler: Add support for LoadElement on strings In JavaScript the [] operator on strings returns a string. QString's operator[] returns a QChar, but we can easily create a string from that. Fixes: QTBUG-103371 Change-Id: Id5c960f00ecc7a5dfe30ccbcaac3ffb2a30308b9 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 18 ++++++++++++++++++ 1 file changed, 18 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 b4993d1752..84c5ad2deb 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -1955,6 +1955,20 @@ void tst_QmlCppCodegen::typedArray() QCOMPARE(o->property("inIntList").toInt(), 2); QCOMPARE(qvariant_cast(o->property("inDateList")), date); QCOMPARE(o->property("inRealList").toDouble(), 30.0); + QCOMPARE(o->property("inCharList").toString(), QStringLiteral("f")); + + const QMetaObject *metaObject = o->metaObject(); + QMetaMethod method = metaObject->method(metaObject->indexOfMethod("stringAt10(QString)")); + QVERIFY(method.isValid()); + + // If LoadElement threw an exception the function would certainly return neither 10 nor 20. + int result = 0; + method.invoke( + o.data(), Q_RETURN_ARG(int, result), Q_ARG(QString, QStringLiteral("a"))); + QCOMPARE(result, 10); + method.invoke( + o.data(), Q_RETURN_ARG(int, result), Q_ARG(QString, QStringLiteral("aaaaaaaaaaa"))); + QCOMPARE(result, 20); } void tst_QmlCppCodegen::prefixedType() @@ -2126,6 +2140,10 @@ void tst_QmlCppCodegen::valueTypeLists() QCOMPARE(qvariant_cast(o->property("intInBounds")), 7); QVERIFY(o->metaObject()->indexOfProperty("intOutOfBounds") > 0); QVERIFY(!o->property("intOutOfBounds").isValid()); + + QCOMPARE(qvariant_cast(o->property("charInBounds")), QStringLiteral("d")); + QVERIFY(o->metaObject()->indexOfProperty("charOutOfBounds") > 0); + QVERIFY(!o->property("charOutOfBounds").isValid()); } void tst_QmlCppCodegen::boundComponents() -- cgit v1.2.3