diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2022-06-06 16:02:15 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-10 10:26:33 +0000 |
commit | a1aed700df5da60ec6eb68952104b1616c905444 (patch) | |
tree | c77ee2591149bf2b1cfb3144e0850d8b38be9d25 /src/quick/items/qquickitemview.cpp | |
parent | f8e07a86c72570ce6d27b726fb83648c5e9dcbf5 (diff) |
Item views: fix error when accessing attached view from non-delegates
Ensure that the view is set on the relevant attached objects before
QQmlComponent::completeCreate() is called, which would otherwise result
in a TypeError because the view would be set too late.
Fixes: QTBUG-104026
Task-number: QTBUG-98718
Change-Id: Ic65370bd4534e7452f2377ab4d60a74badf02079
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit dbd108a7997f129004bbed523db75d4aa9d0ab6c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quick/items/qquickitemview.cpp')
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 449e812060..8cd3f54f44 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -57,8 +57,6 @@ FxViewItem::FxViewItem(QQuickItem *i, QQuickItemView *v, bool own, QQuickItemVie , view(v) , attached(attached) { - if (attached) // can be null for default components (see createComponentItem) - attached->setView(view); } QQuickItemViewChangeSet::QQuickItemViewChangeSet() @@ -2502,12 +2500,29 @@ QQuickItem *QQuickItemViewPrivate::createComponentItem(QQmlComponent *component, item->setZ(zValue); QQml_setParent_noEvent(item, q->contentItem()); item->setParentItem(q->contentItem()); + + initializeComponentItem(item); } if (component) component->completeCreate(); return item; } +/*! + \internal + + Allows derived classes to do any initialization required for \a item + before completeCreate() is called on it. For example, any attached + properties required by the item can be set. + + This is similar to initItem(), but as that has logic specific to + delegate items, we use a separate function for non-delegates. +*/ +void QQuickItemViewPrivate::initializeComponentItem(QQuickItem *item) const +{ + Q_UNUSED(item); +} + void QQuickItemViewPrivate::updateTrackedItem() { Q_Q(QQuickItemView); |