summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-12-18 16:18:16 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2015-01-13 22:52:05 +0100
commit940530ab67a8fd59130b2299fe854707207f041f (patch)
treee6d627cb2b6ed0ba084b38e8db5ec3ee8484fc03 /src/widgets
parent14583137ae445fbfdc82922266f5c0736454f6c4 (diff)
QComboBox: make setModel reset the root model index
When changing models it makes no sense to keep the old root model index, pointing into a possibly deleted model. Reset it to the root of the new model is the best line of action. [ChangeLog][QtWidgets][QComboBox] QComboBox will now reset its root model index when a new model is set on it. Task-number: QTBUG-43350 Change-Id: I113d558ce19fcaed31f13abfbedc7a24302e28d7 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qcombobox.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index a83aecf52c..b38b482295 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -1986,6 +1986,8 @@ void QComboBox::setModel(QAbstractItemModel *model)
this, SLOT(_q_emitHighlighted(QModelIndex)), Qt::UniqueConnection);
}
+ setRootModelIndex(QModelIndex());
+
bool currentReset = false;
if (count()) {
@@ -2024,6 +2026,8 @@ QModelIndex QComboBox::rootModelIndex() const
void QComboBox::setRootModelIndex(const QModelIndex &index)
{
Q_D(QComboBox);
+ if (d->root == index)
+ return;
d->root = QPersistentModelIndex(index);
view()->setRootIndex(index);
update();