diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-11-22 10:25:27 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-11-22 12:15:15 +0100 |
commit | 662ab7ebdad0e6c32278f2fcf9a5e43a11681b09 (patch) | |
tree | aa3aced53fb3bec4c46b0d7a195938556ee4536c | |
parent | 744e77b841878fb017c0f2d60607090008f28180 (diff) |
QQmlDelegateModel: Set extraObject only if required properties given
Otherwise we would set the same object as extraObject and as
contextObject. That spells trouble when tearing down the context.
Fixes: QTBUG-79958
Change-Id: I97fd0bf111304d06cff35eda46d4b4c6eefdaccc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlmodels/qqmldelegatemodel.cpp | 13 | ||||
-rw-r--r-- | tests/auto/quick/qquickrepeater/data/contextProperty.qml | 13 | ||||
-rw-r--r-- | tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp | 24 |
3 files changed, 44 insertions, 6 deletions
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index 531ba18a4b..9cfc80ba4e 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -937,13 +937,14 @@ void PropertyUpdater::breakBinding() void QQDMIncubationTask::initializeRequiredProperties(QQmlDelegateModelItem *modelItemToIncubate, QObject *object) { auto incubatorPriv = QQmlIncubatorPrivate::get(this); - QQmlData *d = QQmlData::get(object); - auto contextData = d ? d->context : nullptr; - if (contextData) { - contextData->hasExtraObject = true; - contextData->extraObject = modelItemToIncubate; - } if (incubatorPriv->hadRequiredProperties()) { + QQmlData *d = QQmlData::get(object); + auto contextData = d ? d->context : nullptr; + if (contextData) { + contextData->hasExtraObject = true; + contextData->extraObject = modelItemToIncubate; + } + if (incubatorPriv->requiredProperties().empty()) return; RequiredProperties &requiredProperties = incubatorPriv->requiredProperties(); diff --git a/tests/auto/quick/qquickrepeater/data/contextProperty.qml b/tests/auto/quick/qquickrepeater/data/contextProperty.qml new file mode 100644 index 0000000000..44e76f474f --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/contextProperty.qml @@ -0,0 +1,13 @@ +import QtQuick 2.14 + +Item { + Column { + Repeater { + model: ["apples", "oranges", "pears"] + Text { + id: txt + text: modelData + index + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index ccfef63902..33b8742170 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -81,6 +81,7 @@ private slots: void package(); void ownership(); void requiredProperties(); + void contextProperties(); }; class TestObject : public QObject @@ -1131,6 +1132,29 @@ void tst_QQuickRepeater::requiredProperties() QVERIFY(o); } +void tst_QQuickRepeater::contextProperties() +{ + QQmlEngine engine; + + QQmlComponent component(&engine, testFileUrl("contextProperty.qml")); + QScopedPointer<QObject> o {component.create()}; + QVERIFY(o); + + auto *root = qobject_cast<QQuickItem *>(o.get()); + QVERIFY(root); + + QQueue<QQuickItem *> items; + items.append(root); + + while (!items.isEmpty()) { + QQuickItem *item = items.dequeue(); + QQmlContextData *data = QQmlContextData::get(qmlContext(item)); + QVERIFY(!data->hasExtraObject); + for (QQuickItem *child : item->childItems()) + items.enqueue(child); + } +} + QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" |