aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-11-08 17:00:38 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-11-13 11:58:50 +0100
commit12fb7d27431a7db2a19e1954c85d5dc03264b356 (patch)
tree5e998ab686c48c3c2d49084cb1eafd5e26c28e97 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent9c2fc83be55647e0519cdbd6b19701fa022743e7 (diff)
QtQml: Fix calling of method with QML_USING types
On the engine side, types made available with QML_USING are recognizable by their QMetaType conversions. In order to actually call the right methods, we need to slightly prefer methods to whose arguments we can convert over ones we have not idea about. This, however, adds the problem of converting to QString, double, QVariant and QJSValue, which is possible for any type. Since such conversions are less specific than manually added converters, we de-prioritize them a bit. On the compiler side we need to transmit the knowledge about the overload to be called from the compiler (which has already done its own overload selection) to the lookup methods. This is easily done using the relative method index. This way we do not need to do any run time overload selection at all and we do not need to pass any types to the lookup methods. We can do this without further compatibility adaptations because the current version of those lookup methods was only introduced in 6.9. Excluded, of course, are shadowable calls, which are performed with only QVariant arguments. These carry the arguments themselves and trigger the engine's overload selection. Internally nothing changes about them. Passing a list of QMetaType::fromType<QVariant>() to the lookup methods for them has always been a waste. Only the engine changes are relevant for 6.8. In 6.8, the lookup methods defer the overload selection to the engine and take the types on every call. We still cannot separate the engine changes from the compiler changes in dev because the same test is run once in interpreted and once in compiled mode. Pick-to: 6.8 Task-number: QTBUG-127174 Change-Id: I6ab52ddf3be65dcc94547266c5dcc5ac1050c93c Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 0ea7346746..6b6283b854 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -4235,24 +4235,39 @@ void tst_QmlCppCodegen::qmlUsing()
QVERIFY(u);
QCOMPARE(u->a(), 7);
+ QCOMPARE(u->getB(), 5);
QCOMPARE(u->val().a(), 24);
+ QCOMPARE(u->val().getB(), 25);
QCOMPARE(u->property("valA").toInt(), 24);
QCOMPARE(u->property("myA").toInt(), 7);
+ QCOMPARE(u->property("myB").toInt(), 5);
QCOMPARE(u->property("myA2").toInt(), 7);
+ QCOMPARE(u->property("myB2").toInt(), 5);
QList<int> as;
- QObject::connect(u, &UsingUserObject::aChanged, this, [&]() { as.append(u->a()); });
+ QList<int> bs;
+ QObject::connect(u, &UsingUserObject::aChanged, this, [&]() {
+ as.append(u->a());
+ bs.append(u->getB());
+ });
QMetaObject::invokeMethod(object.data(), "twiddle");
- const QList<int> expected = { 57, 59 };
- QCOMPARE(as, expected);
+ const QList<int> expectedA = { 57, 59 };
+ QCOMPARE(as, expectedA);
+
+ const QList<int> expectedB = { 5, 58 };
+ QCOMPARE(bs, expectedB);
QCOMPARE(u->a(), 59);
+ QCOMPARE(u->getB(), 60);
QCOMPARE(u->val().a(), 55);
+ QCOMPARE(u->val().getB(), 25);
QCOMPARE(u->property("valA").toInt(), 55);
QCOMPARE(u->property("myA").toInt(), 59);
+ QCOMPARE(u->property("myB").toInt(), 5); // Remains 5, due to lack of signaling
QCOMPARE(u->property("myA2").toInt(), 59);
+ QCOMPARE(u->property("myB2").toInt(), 5); // Remains 5, due to lack of signaling
}
void tst_QmlCppCodegen::qtfont()