diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-04-21 10:34:03 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-04-22 14:31:40 +0200 |
commit | 796f6e1e8e99ea1046ffe2a744cfd1dca1248258 (patch) | |
tree | f0c17669b3e86a977596adbd9d0269491a3ddbd1 | |
parent | 327b489bd7b137aa6bce5e16ba3d47fe3f33f33c (diff) |
QQuickRepeater: Fix interaction with Package
Amends 3b806a18cc665b5ae0e12d45fe170bfc3f00352a.
Eric's change tried to tackle the issue by making the PartModel more
well-behaved. However, this still left some issues, as exhibited by the
linked bug. This time, we simply make the repeater more robust, and
setup d->deletables if it's not done yet.
Pick-to: 5.15
Fixes: QTBUG-71964
Change-Id: I58c80c84f73fddaea5d6030f92ffff219ecf2b71
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
(cherry picked from commit 28a31148ca02dbb530fd92dfafbcf71c64af4b70)
-rw-r--r-- | src/quick/items/qquickrepeater.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickrepeater/data/package2.qml | 36 | ||||
-rw-r--r-- | tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp | 10 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp index 20603720c5..6dc735d20b 100644 --- a/src/quick/items/qquickrepeater.cpp +++ b/src/quick/items/qquickrepeater.cpp @@ -417,6 +417,12 @@ void QQuickRepeater::createdItem(int index, QObject *) void QQuickRepeater::initItem(int index, QObject *object) { Q_D(QQuickRepeater); + if (index >= d->deletables.size()) { + // this can happen when Package is used + // calling regenerate does too much work, all we need is to call resize + // so that d->deletables[index] = item below works + d->deletables.resize(d->model->count() + 1); + } QQuickItem *item = qmlobject_cast<QQuickItem*>(object); if (!d->deletables.at(index)) { diff --git a/tests/auto/quick/qquickrepeater/data/package2.qml b/tests/auto/quick/qquickrepeater/data/package2.qml new file mode 100644 index 0000000000..0ceb34b362 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/package2.qml @@ -0,0 +1,36 @@ +import QtQuick 2.0 +import QtQml.Models 2.2 +import QtQuick.Window 2.0 + +Item { + width: 300 + height: 300 + visible: true + DelegateModel { + id: mdl + + model: 1 + delegate: Package { + Item { + id: first + Package.name: "first" + } + Item{ + id: second + Package.name: "second" + } + } + } + + Repeater { + model: mdl.parts.first + } + Repeater { + model: mdl.parts.second + } + + function setup(): bool { + mdl.model = 2 + return true; + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index 33b8742170..35883339d7 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -1056,6 +1056,16 @@ void tst_QQuickRepeater::package() QCOMPARE(repeater2->count(), 1); QCOMPARE(repeater2->itemAt(0)->objectName(), "secondItem"); } + + { + QQmlComponent component(&engine, testFileUrl("package2.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root != nullptr); + bool returnedValue = false; + // calling setup should not crash + QMetaObject::invokeMethod(root.get(), "setup", Q_RETURN_ARG(bool, returnedValue)); + QVERIFY(returnedValue); + } } void tst_QQuickRepeater::ownership() |