summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels/qstandarditemmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemmodels/qstandarditemmodel.cpp')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index 2998808b54..9bdc22b49e 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -138,10 +138,19 @@ void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item,
return;
}
}
+
+ // setting the model to nullptr invalidates the persistent index which we want to avoid
+ if (!item && oldItem)
+ oldItem->d_func()->setModel(nullptr);
+
+ children.replace(index, item);
+
+ // since now indexFromItem() does no longer return a valid index, the persistent index
+ // will not be invalidated anymore
if (oldItem)
oldItem->d_func()->setModel(nullptr);
delete oldItem;
- children.replace(index, item);
+
if (item)
item->d_func()->lastKnownIndex = index;