aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqml.cpp3
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml48
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp16
4 files changed, 67 insertions, 1 deletions
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp
index d5e98f1805..5e99f92bc7 100644
--- a/src/qml/qml/qqml.cpp
+++ b/src/qml/qml/qqml.cpp
@@ -1022,7 +1022,8 @@ static ObjectLookupResult initObjectLookup(
// & 1 to tell the gc that this is not heap allocated; see markObjects in qv4lookup_p.h
l->qobjectFallbackLookup.metaObject = quintptr(metaObject) + 1;
l->qobjectFallbackLookup.coreIndex = coreIndex;
- l->qobjectFallbackLookup.notifyIndex = property.notifySignalIndex();
+ l->qobjectFallbackLookup.notifyIndex =
+ QMetaObjectPrivate::signalIndex(property.notifySignal());
l->qobjectFallbackLookup.isConstant = property.isConstant() ? 1 : 0;
return ObjectLookupResult::Fallback;
}
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 4c11b161db..30555762c7 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -143,6 +143,7 @@ set(qml_files
shifts.qml
signal.qml
signalHandler.qml
+ signalIndexMismatch.qml
signatureIgnored.qml
specificParent.qml
stringArg.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml b/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml
new file mode 100644
index 0000000000..ecc03026ba
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml
@@ -0,0 +1,48 @@
+import QtQuick
+import QtQml.Models
+
+Item {
+ property var visualIndexBeforeMove: [-1, -1, -1]
+ property var visualIndexAfterMove: [-1, -1, -1]
+
+ DelegateModel {
+ id: visualModel
+ model: ListModel {
+ ListElement { name: "Apple (id 0)" }
+ ListElement { name: "Orange (id 1)" }
+ ListElement { name: "Banana (id 2)" }
+ }
+
+ delegate: DropArea {
+ id: delegateRoot
+
+ required property string name
+ // property that was not updated correctly in QTBUG-104047
+ readonly property int visualIndex: DelegateModel.itemsIndex
+ Rectangle {
+ id: child
+
+ readonly property int visualIndex: delegateRoot.visualIndex
+ }
+ }
+ }
+
+ Repeater {
+ id: root
+ model: visualModel
+ }
+
+ Component.onCompleted: {
+ visualIndexBeforeMove[0] = root.itemAt(0).visualIndex
+ visualIndexBeforeMove[1] = root.itemAt(1).visualIndex
+ visualIndexBeforeMove[2] = root.itemAt(2).visualIndex
+ visualModel.items.move(2, 0)
+ // test that bindings on the QQmlDelegateModelAttached are captured properly:
+ // after the move, the visualIndex property should be updated to the new value,
+ // which in this case is also the index used in itemAt()
+ visualIndexAfterMove[0] = root.itemAt(0).visualIndex
+ visualIndexAfterMove[1] = root.itemAt(1).visualIndex
+ visualIndexAfterMove[2] = root.itemAt(2).visualIndex
+ }
+
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 8bb88e624c..85490f3ab3 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -143,6 +143,7 @@ private slots:
void signatureIgnored();
void listAsArgument();
void letAndConst();
+ void signalIndexMismatch();
};
void tst_QmlCppCodegen::initTestCase()
@@ -2777,6 +2778,21 @@ void tst_QmlCppCodegen::letAndConst()
QCOMPARE(o->objectName(), u"ab"_s);
}
+void tst_QmlCppCodegen::signalIndexMismatch()
+{
+ QQmlEngine engine;
+
+ QQmlComponent c1(&engine, QUrl(u"qrc:/qt/qml/TestTypes/signalIndexMismatch.qml"_s));
+ QVERIFY2(c1.isReady(), qPrintable(c1.errorString()));
+
+ QScopedPointer<QObject> item(c1.create());
+ const auto visualIndexBeforeMoveList = item->property("visualIndexBeforeMove").toList();
+ const auto visualIndexAfterMoveList = item->property("visualIndexAfterMove").toList();
+
+ QCOMPARE(visualIndexBeforeMoveList, QList<QVariant>({ 0, 1, 2 }));
+ QCOMPARE(visualIndexAfterMoveList, QList<QVariant>({ 0, 1, 2 }));
+};
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"