aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-03-21 11:20:32 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-03-28 12:40:51 +0100
commitfff113b4a3259ed558e97bc66ecdacd7455dc490 (patch)
tree87dd1a378582dd1415d21e77faea44147cbd6919
parent280a3372fd76acd662fc116f9794d2452b770fee (diff)
QQmlListWrapper: Don't use QQmlListReference for virtualGetLength()
We cannot use QQmlListReference on detached list properties. Also, it's wasteful. Pick-to: 6.7 Fixes: QTBUG-118076 Change-Id: I754f19ed8c3f6eae1b3613f6866f3cf792cee8cf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
-rw-r--r--src/qml/qml/qqmllistwrapper.cpp5
-rw-r--r--tests/auto/qml/qqmllistreference/data/consoleLogSyntheticList.qml8
-rw-r--r--tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp12
3 files changed, 23 insertions, 2 deletions
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp
index 7102c4ee16..8d5a585b62 100644
--- a/src/qml/qml/qqmllistwrapper.cpp
+++ b/src/qml/qml/qqmllistwrapper.cpp
@@ -198,8 +198,9 @@ ReturnedValue QmlListWrapper::virtualGet(const Managed *m, PropertyKey id, const
qint64 QmlListWrapper::virtualGetLength(const Managed *m)
{
Q_ASSERT(m->as<QmlListWrapper>());
- const QmlListWrapper *w = static_cast<const QmlListWrapper *>(m);
- return w->toListReference().size();
+ QQmlListProperty<QObject> *property = static_cast<const QmlListWrapper *>(m)->d()->property();
+ Q_ASSERT(property);
+ return property->count ? property->count(property) : 0;
}
bool QmlListWrapper::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver)
diff --git a/tests/auto/qml/qqmllistreference/data/consoleLogSyntheticList.qml b/tests/auto/qml/qqmllistreference/data/consoleLogSyntheticList.qml
new file mode 100644
index 0000000000..9d2fd3e0b2
--- /dev/null
+++ b/tests/auto/qml/qqmllistreference/data/consoleLogSyntheticList.qml
@@ -0,0 +1,8 @@
+import QtQml
+
+QtObject {
+ id: self
+
+ function createList() : list<QtObject> { return [self] }
+ Component.onCompleted: console.log(createList())
+}
diff --git a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
index 25c3f9e5f4..76711a00e6 100644
--- a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
+++ b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
@@ -60,6 +60,7 @@ private slots:
void jsArrayMethodsWithParams();
void listIgnoresNull_data() { modeData(); }
void listIgnoresNull();
+ void consoleLogSyntheticList();
};
class TestType : public QObject
@@ -1082,6 +1083,17 @@ void tst_qqmllistreference::listIgnoresNull()
QVERIFY(object != nullptr);
}
+void tst_qqmllistreference::consoleLogSyntheticList()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("consoleLogSyntheticList.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QTest::ignoreMessage(
+ QtDebugMsg, QRegularExpression("\\[QObject_QML_[0-9]+\\(0x[0-9a-f]+\\)\\]"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+}
+
QTEST_MAIN(tst_qqmllistreference)
#include "tst_qqmllistreference.moc"