From 2713a4534bc4b26e0d3931385845a2117aef0d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Martsum?= Date: Mon, 8 Jul 2013 11:29:35 +0200 Subject: [PATCH] QListWidget - iterator fix in QListModel::ensureSorted This is a fix similar to 7ddf1b14ecc7e56ddcc78cc7057881d7925d20ff Change-Id: I369f428252527a8c3326c0f23a1dc31b63f884f5 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qlistwidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 39d03124ce..1573e97981 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -347,7 +347,11 @@ void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int en bool changed = false; for (int i = 0; i < count; ++i) { int oldRow = sorting.at(i).second; + int tmpitepos = lit - tmp.begin(); QListWidgetItem *item = tmp.takeAt(oldRow); + if (tmpitepos > tmp.size()) + --tmpitepos; + lit = tmp.begin() + tmpitepos; lit = sortedInsertionIterator(lit, tmp.end(), order, item); int newRow = qMax(lit - tmp.begin(), 0); lit = tmp.insert(lit, item);