Skip to content

Commit cc084a1

Browse files
author
Martin Jones
committed
Adding items to a view with no delegate crashes.
If there is no delegate then clear state and return. Change-Id: I786b9bc4018706797056fbd1ad25d25663102707 Task-number: QTBUG-22379 Reviewed-by: Andrew den Exter
1 parent c14af1c commit cc084a1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/declarative/graphicsitems/qdeclarativegridview.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,11 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
28522852
addedVisible = true;
28532853
}
28542854
FxGridItem *item = d->createItem(modelIndex + i);
2855+
if (!item) {
2856+
// broken or no delegate
2857+
d->clear();
2858+
return;
2859+
}
28552860
d->visibleItems.insert(index, item);
28562861
item->setPosition(colPos, rowPos);
28572862
added.append(item);
@@ -3042,6 +3047,11 @@ void QDeclarativeGridView::itemsMoved(int from, int to, int count)
30423047
FxGridItem *movedItem = moved.take(item->index);
30433048
if (!movedItem)
30443049
movedItem = d->createItem(item->index);
3050+
if (!movedItem) {
3051+
// broken or no delegate
3052+
d->clear();
3053+
return;
3054+
}
30453055
it = d->visibleItems.insert(it, movedItem);
30463056
if (it == d->visibleItems.begin() && firstItem)
30473057
movedItem->setPosition(firstItem->colPos(), firstItem->rowPos());

src/declarative/graphicsitems/qdeclarativelistview.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,11 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
32833283
addedVisible = true;
32843284
}
32853285
FxListItem *item = d->createItem(modelIndex + i);
3286+
if (!item) {
3287+
// broken or no delegate
3288+
d->clear();
3289+
return;
3290+
}
32863291
d->visibleItems.insert(insertionIdx, item);
32873292
pos -= item->size() + d->spacing;
32883293
item->setPosition(pos);
@@ -3313,6 +3318,11 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
33133318
addedVisible = true;
33143319
}
33153320
FxListItem *item = d->createItem(modelIndex + i);
3321+
if (!item) {
3322+
// broken or no delegate
3323+
d->clear();
3324+
return;
3325+
}
33163326
d->visibleItems.insert(index, item);
33173327
item->setPosition(pos);
33183328
added.append(item);
@@ -3516,6 +3526,11 @@ void QDeclarativeListView::itemsMoved(int from, int to, int count)
35163526
FxListItem *movedItem = moved.take(item->index);
35173527
if (!movedItem)
35183528
movedItem = d->createItem(item->index);
3529+
if (!movedItem) {
3530+
// broken or no delegate
3531+
d->clear();
3532+
return;
3533+
}
35193534
if (item->index <= firstVisible->index)
35203535
moveBy -= movedItem->size();
35213536
it = d->visibleItems.insert(it, movedItem);

0 commit comments

Comments
 (0)