aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicklistview.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-06-06 16:02:15 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-10 10:26:33 +0000
commita1aed700df5da60ec6eb68952104b1616c905444 (patch)
treec77ee2591149bf2b1cfb3144e0850d8b38be9d25 /src/quick/items/qquicklistview.cpp
parentf8e07a86c72570ce6d27b726fb83648c5e9dcbf5 (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.cpp10
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)
{