diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 40cf2f0f95..a83aecf52c 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -1931,6 +1931,9 @@ void QComboBox::setModel(QAbstractItemModel *model) return; } + if (model == d->model) + return; + #ifndef QT_NO_COMPLETER if (d->lineEdit && d->lineEdit->completer() && d->lineEdit->completer() == d->completer) diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index ac32ee4968..556602b523 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -1576,6 +1576,12 @@ void tst_QComboBox::setModel() box.setModel(new QStandardItemModel(2,1, &box)); QCOMPARE(box.currentIndex(), 0); QVERIFY(box.model() != oldModel); + + // check that setting the very same model doesn't move the current item + box.setCurrentIndex(1); + QCOMPARE(box.currentIndex(), 1); + box.setModel(box.model()); + QCOMPARE(box.currentIndex(), 1); } void tst_QComboBox::setCustomModelAndView()