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>
This commit is contained in:
J-P Nurmi 2016-01-13 18:03:43 +01:00
parent 70a31cdafb
commit 29a75074ab
1 changed files with 9 additions and 8 deletions

View File

@ -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) :