From 78043b57ac50a399222221fb8fad2a47ff90a10c Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 1 Nov 2011 16:10:02 +0100 Subject: Ensure that using multiple GridViews with the same model source works When the same model source is used in multiple GridViews then it can get into a state where items that have been inserted are removed from a list which it then later tries to access to emit signals for. This patch ensures that a list of the items that the signal is emitted for is kept before any of the wrapper items are potentially deleted so that the signals can be emitted as expected correctly. Task-number: QTBUG-22271 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index feca6b5..6a2816a 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2885,6 +2885,10 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) } } + QList addedItems; + for (int j = 0; j < added.count(); ++j) + addedItems << added.at(j)->attached; + if (d->itemCount && d->currentIndex >= modelIndex) { // adjust current item index d->currentIndex += count; @@ -2898,8 +2902,8 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) } // everything is in order now - emit add() signal - for (int j = 0; j < added.count(); ++j) - added.at(j)->attached->emitAdd(); + for (int j = 0; j < addedItems.count(); ++j) + addedItems.at(j)->emitAdd(); d->itemCount += count; emit countChanged(); -- cgit v0.12