From cc084a1a05c53035bf401aed2e08e3c30a75e509 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 27 Oct 2011 15:22:45 +1000 Subject: 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 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 10 ++++++++++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 29c714d..feca6b5 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2852,6 +2852,11 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) addedVisible = true; } FxGridItem *item = d->createItem(modelIndex + i); + if (!item) { + // broken or no delegate + d->clear(); + return; + } d->visibleItems.insert(index, item); item->setPosition(colPos, rowPos); added.append(item); @@ -3042,6 +3047,11 @@ void QDeclarativeGridView::itemsMoved(int from, int to, int count) FxGridItem *movedItem = moved.take(item->index); if (!movedItem) movedItem = d->createItem(item->index); + if (!movedItem) { + // broken or no delegate + d->clear(); + return; + } it = d->visibleItems.insert(it, movedItem); if (it == d->visibleItems.begin() && firstItem) movedItem->setPosition(firstItem->colPos(), firstItem->rowPos()); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 920b6ae..37c34dc 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -3283,6 +3283,11 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) addedVisible = true; } FxListItem *item = d->createItem(modelIndex + i); + if (!item) { + // broken or no delegate + d->clear(); + return; + } d->visibleItems.insert(insertionIdx, item); pos -= item->size() + d->spacing; item->setPosition(pos); @@ -3313,6 +3318,11 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) addedVisible = true; } FxListItem *item = d->createItem(modelIndex + i); + if (!item) { + // broken or no delegate + d->clear(); + return; + } d->visibleItems.insert(index, item); item->setPosition(pos); added.append(item); @@ -3516,6 +3526,11 @@ void QDeclarativeListView::itemsMoved(int from, int to, int count) FxListItem *movedItem = moved.take(item->index); if (!movedItem) movedItem = d->createItem(item->index); + if (!movedItem) { + // broken or no delegate + d->clear(); + return; + } if (item->index <= firstVisible->index) moveBy -= movedItem->size(); it = d->visibleItems.insert(it, movedItem); -- cgit v0.12