From 75f957f87a9341af5d3266166ae9996dbf79da2b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 13 Sep 2021 14:05:29 +0200 Subject: [PATCH] QQmlListModel: Don't return from the middle of a loop We still have to process the other properties there. Pick-to: 6.2 Change-Id: I043596dc55de885e6b746020633ec8b97d043ff2 Reviewed-by: Fabian Kosmale --- src/qmlmodels/qqmllistmodel.cpp | 11 +++++------ tests/auto/qml/qqmllistmodel/data/urls.qml | 11 +++++++++-- tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp index 4ae6b011fa..b9f59040a1 100644 --- a/src/qmlmodels/qqmllistmodel.cpp +++ b/src/qmlmodels/qqmllistmodel.cpp @@ -723,14 +723,13 @@ void ListModel::set(int elementIndex, QV4::Object *object, ListModel::SetElement if (maybeUrl.metaType() == QMetaType::fromType()) { const QUrl qurl = maybeUrl.toUrl(); const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Url); - if (r.type == ListLayout::Role::Url) { + if (r.type == ListLayout::Role::Url) e->setUrlPropertyFast(r, qurl); - } - return; + } else { + const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap); + if (role.type == ListLayout::Role::VariantMap) + e->setVariantMapFast(role, o); } - const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap); - if (role.type == ListLayout::Role::VariantMap) - e->setVariantMapFast(role, o); } } else if (propertyValue->isNullOrUndefined()) { if (reason == SetElement::WasJustInserted) { diff --git a/tests/auto/qml/qqmllistmodel/data/urls.qml b/tests/auto/qml/qqmllistmodel/data/urls.qml index b7fe57402e..9e59a70cb6 100644 --- a/tests/auto/qml/qqmllistmodel/data/urls.qml +++ b/tests/auto/qml/qqmllistmodel/data/urls.qml @@ -4,16 +4,23 @@ import QtQml.Models 2 Item { id: root readonly property url url1: "http://qt-project.org" + property var result1 property var result2 + + property var alive1 + property var alive2 + ListModel {id: myModel} Component.onCompleted: { - myModel.append({"url": new URL("http://qt.io")}) - myModel.append({"url": url1}) + myModel.append({"url": new URL("http://qt.io"), "alive": "indeed"}) + myModel.append({"url": url1, "alive": "and kicking"}) const entry1 = myModel.get(0) root.result1 = entry1.url; + root.alive1 = entry1.alive; const entry2 = myModel.get(1) root.result2 = entry2.url; + root.alive2 = entry2.alive; } } diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index fae2b8da63..6896965eea 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -1408,6 +1408,8 @@ void tst_qqmllistmodel::url() QVERIFY(o); QCOMPARE(o->property("result1").toUrl(), QUrl("http://qt.io")); QCOMPARE(o->property("result2").toUrl(), QUrl("http://qt-project.org")); + QCOMPARE(o->property("alive1").toString(), QStringLiteral("indeed")); + QCOMPARE(o->property("alive2").toString(), QStringLiteral("and kicking")); } void tst_qqmllistmodel::datetime()