aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickcombobox.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-13 18:03:43 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-14 10:40:18 +0000
commit29a75074abcd452185e82623cf927d9be6a4d1b8 (patch)
tree20e472df7c70899e1b7042b2a39faed7232aedd6 /src/templates/qquickcombobox.cpp
parent70a31cdafbdb3f018e10465ccb9a481d6fa54ab5 (diff)
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 <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcombobox.cpp')
-rw-r--r--src/templates/qquickcombobox.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/templates/qquickcombobox.cpp b/src/templates/qquickcombobox.cpp
index a2c0bf89..ec8b94f1 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) :