on xenial help sign in
Fix crash if a component that is not an Item is given to sectionDelegate
21a217dAlbert Astals Cid
plugins/Dash/listviewwithpageheader.cpp+6−4
@@ -287,9 +287,11 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
287 m_sectionDelegate = delegate;
287 m_sectionDelegate = delegate;
288
288
289 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
289 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
290+ if (m_topSectionItem) {
290− m_topSectionItem->setZ(3);
291+ m_topSectionItem->setZ(3);
291− QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
292+ QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
292− connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
293+ connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
294+ }
293
295
294 // TODO create sections for existing items
296 // TODO create sections for existing items
295
297
@@ -776,7 +778,7 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
776 }
778 }
777 m_sectionDelegate->completeCreate();
779 m_sectionDelegate->completeCreate();
778
780
779− if (watchGeometry) {
781+ if (watchGeometry && sectionItem) {
780 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
782 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
781 }
783 }
782
784
tests/plugins/Dash/listviewwithpageheadersectiontest.cpp+6
@@ -2195,6 +2195,12 @@ private Q_SLOTS:
2195 verifyItem(1, 240., 220., false, "halfheight", false);
2195 verifyItem(1, 240., 220., false, "halfheight", false);
2196 }
2196 }
2197
2197
2198+ void testInvalidSectionDelegate()
2199+ {
2200+ lvwph->setProperty("useBrokenSectionDelegateComponent", true);
2201+ scrollToBottom();
2202+ }
2203+
2198private:
2204private:
2199 QQuickView *view;
2205 QQuickView *view;
2200 ListViewWithPageHeader *lvwph;
2206 ListViewWithPageHeader *lvwph;
tests/plugins/Dash/listviewwithpageheadertestsection.qml+12−1
@@ -94,8 +94,13 @@ Rectangle {
94 }
94 }
95 }
95 }
96
96
97+ property bool useBrokenSectionDelegateComponent: false
97 sectionProperty: "type"
98 sectionProperty: "type"
99+ sectionDelegate: useBrokenSectionDelegateComponent ? objectComponent
100+ : regularSectionDelegateComponent
101+
98− sectionDelegate: Component {
102+ Component {
103+ id: regularSectionDelegateComponent
99 Rectangle {
104 Rectangle {
100 property alias text: theText.text
105 property alias text: theText.text
101 color: "green"
106 color: "green"
@@ -104,5 +109,11 @@ Rectangle {
104 anchors { left: parent.left; right: parent.right }
109 anchors { left: parent.left; right: parent.right }
105 }
110 }
106 }
111 }
112+
113+ Component {
114+ id: objectComponent
115+ QtObject {
116+ }
117+ }
107 }
118 }
108}
119}