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/qquicklistview.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/qquicklistview.cpp')
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index fa52f48825..14ff95163f 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -130,6 +130,8 @@ public: bool hasStickyHeader() const override; bool hasStickyFooter() const override; + void initializeComponentItem(QQuickItem *item) const override; + void changedVisibleIndex(int newIndex) override; void initializeCurrentItem() override; @@ -1573,6 +1575,14 @@ bool QQuickListViewPrivate::hasStickyFooter() const return footer && footerPositioning != QQuickListView::InlineFooter; } +void QQuickListViewPrivate::initializeComponentItem(QQuickItem *item) const +{ + QQuickListViewAttached *attached = static_cast<QQuickListViewAttached *>( + qmlAttachedPropertiesObject<QQuickListView>(item)); + if (attached) // can be null for default components (see createComponentItem) + attached->setView(const_cast<QQuickListView*>(q_func())); +} + void QQuickListViewPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry) { |