From 29a75074abcd452185e82623cf927d9be6a4d1b8 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 13 Jan 2016 18:03:43 +0100 Subject: [PATCH] ComboBox: fix delegate model re-creation Instead of deleting the old model first and then immediately creating a new model, create the new model first, and then destroy the old one afterwards. This simple trick ensures that the new model doesn't land to the same memory address where the old model was allocated, which in turn made QQuickItemView think the model didn't change. Change-Id: Ic1ba1345d50b62a93309e4c3f201152ce57d0412 Task-number: QTBUG-50385 Task-number: QTBUG-50386 Reviewed-by: J-P Nurmi --- src/templates/qquickcombobox.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/templates/qquickcombobox.cpp b/src/templates/qquickcombobox.cpp index a2c0bf892a..ec8b94f159 100644 --- a/src/templates/qquickcombobox.cpp +++ b/src/templates/qquickcombobox.cpp @@ -287,14 +287,12 @@ void QQuickComboBoxPrivate::setHighlightedIndex(int index) void QQuickComboBoxPrivate::createDelegateModel() { Q_Q(QQuickComboBox); - if (delegateModel) { - if (ownModel) { - delete delegateModel; - } else { - disconnect(delegateModel, &QQmlInstanceModel::countChanged, this, &QQuickComboBoxPrivate::countChanged); - disconnect(delegateModel, &QQmlInstanceModel::modelUpdated, this, &QQuickComboBoxPrivate::updateCurrentText); - disconnect(delegateModel, &QQmlInstanceModel::initItem, this, &QQuickComboBoxPrivate::initItem); - } + bool ownedOldModel = ownModel; + QQmlInstanceModel* oldModel = delegateModel; + if (oldModel) { + disconnect(delegateModel, &QQmlInstanceModel::countChanged, this, &QQuickComboBoxPrivate::countChanged); + disconnect(delegateModel, &QQmlInstanceModel::modelUpdated, this, &QQuickComboBoxPrivate::updateCurrentText); + disconnect(delegateModel, &QQmlInstanceModel::initItem, this, &QQuickComboBoxPrivate::initItem); } ownModel = false; @@ -318,6 +316,9 @@ void QQuickComboBoxPrivate::createDelegateModel() } emit q->delegateModelChanged(); + + if (ownedOldModel) + delete oldModel; } QQuickComboBox::QQuickComboBox(QQuickItem *parent) :