diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-05-08 14:59:27 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-05-09 21:28:07 +0200 |
commit | 71b4a5e6dfe07fe30c59b3e84c9db27f443a7b92 (patch) | |
tree | f560cd6a67c7f555a00a1d03d495e854e9196573 | |
parent | 41f36038fb2618561b2405efbdaf7ccd5bf3769d (diff) | |
download | qtdeclarative-71b4a5e6dfe07fe30c59b3e84c9db27f443a7b92.tar.gz |
QmlCompiler: Re-allow conversion from QObject to QString
It only worked for the console functions in 6.5. There it was suppressed
by the enforcement of type conversions in the basic blocks pass in dev.
We have, however, a good enough way to coerce QObject to QString these
days.
Task-number: QTBUG-112291
Change-Id: I025976cc7fbe430c5cdc607cae3ca48838b24f88
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
4 files changed, 11 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp index b48749a96b..7fb37f3dfa 100644 --- a/src/qmlcompiler/qqmljstyperesolver.cpp +++ b/src/qmlcompiler/qqmljstyperesolver.cpp @@ -1087,7 +1087,7 @@ bool QQmlJSTypeResolver::canPrimitivelyConvertFromTo( if (isNumeric(from) && equals(to, m_boolType)) return true; if (from->accessSemantics() == QQmlJSScope::AccessSemantics::Reference - && equals(to, m_boolType)) { + && (equals(to, m_boolType) || equals(to, m_stringType))) { return true; } diff --git a/tests/auto/qml/qmlcppcodegen/data/failures.qml b/tests/auto/qml/qmlcppcodegen/data/failures.qml index 2ff520cd73..b19b7f9ea2 100644 --- a/tests/auto/qml/qmlcppcodegen/data/failures.qml +++ b/tests/auto/qml/qmlcppcodegen/data/failures.qml @@ -30,8 +30,6 @@ QtObject { Component.onCompleted: doesNotExist() - property string aString: self + "a" - property BirthdayParty party: BirthdayParty { onPartyStarted: (foozle) => { objectName = foozle } } diff --git a/tests/auto/qml/qmlcppcodegen/data/sequenceToIterable.qml b/tests/auto/qml/qmlcppcodegen/data/sequenceToIterable.qml index b73f184211..23e2645128 100644 --- a/tests/auto/qml/qmlcppcodegen/data/sequenceToIterable.qml +++ b/tests/auto/qml/qmlcppcodegen/data/sequenceToIterable.qml @@ -12,6 +12,7 @@ Item { Item { required property int index required property QtObject modelData + objectName: modelData + ": " + index } } diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 5c511ef10c..7de1b4407d 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -3280,6 +3280,15 @@ void tst_QmlCppCodegen::sequenceToIterable() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); QCOMPARE(object->property("c").toInt(), 11); + + QQmlListReference children(object.data(), "children"); + QCOMPARE(children.count(), 11); + static const QRegularExpression name("Entry\\(0x[0-9a-f]+, \"Item ([0-9])\"\\): ([0-9])"); + for (int i = 0; i < 10; ++i) { + const auto match = name.match(children.at(i)->objectName()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1), QString::number(i)); + } } void tst_QmlCppCodegen::shadowedMethod() |