Fix possible crash when disabling grouping
Review Request #111919 - Created Aug. 6, 2013 and submitted
Sometimes when enabling and then disabling grouping, I get a crash. I think the problem is that KItemListView::slotGroupedSortingChanged(bool current) uses a QMutableHashIterator to iterate through the groups while they are being removed. The problem is that they are not removed using the iterator, but by another function inside the loop. The iterator can thus become invalid, and iterating further can cause all sorts of trouble if we are unlucky. The solution is to use a QHashIterator. This iterator creates an internal copy of the container which is not modified when elements are being removed.
Cannot reproduce the crash any more.
I can't reproduce it with your suggestions in the bug report or even with some creative group enabling/disabling.. I guess it's just a rare crash. But the patch seems OK to me. Not giving a ship it because i don't know the code in which you made the change.
I can't reproduce it either. Tested with 123 items grouped in 25 groups. > The solution is to use a QHashIterator. This iterator creates an internal copy of the container which is not modified when elements are being removed. This makes sense, but can you please add this comment to the modified code? So that everybody knows, why we use a QHashIterator and not a QMutableHashIterator here. Thanks.