aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp11
-rw-r--r--tests/auto/controls/data/tst_combobox.qml29
2 files changed, 38 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 836d6806..cce61509 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -669,9 +669,16 @@ void QQuickComboBox::setPopup(QQuickPopup *popup)
QString QQuickComboBox::textAt(int index) const
{
Q_D(const QQuickComboBox);
- if (!d->delegateModel || index < 0 || index >= d->delegateModel->count() || !d->delegateModel->object(index))
+ if (!d->delegateModel || index < 0 || index >= d->delegateModel->count())
return QString();
- return d->delegateModel->stringValue(index, d->textRole.isEmpty() ? QStringLiteral("modelData") : d->textRole);
+
+ QString text;
+ QObject *object = d->delegateModel->object(index);
+ if (object) {
+ text = d->delegateModel->stringValue(index, d->textRole.isEmpty() ? QStringLiteral("modelData") : d->textRole);
+ d->delegateModel->release(object);
+ }
+ return text;
}
/*!
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 38858998..d21e9900 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -811,4 +811,33 @@ TestCase {
control.destroy()
}
+
+ ListModel {
+ id: resetmodel
+ ListElement { text: "First" }
+ ListElement { text: "Second" }
+ ListElement { text: "Third" }
+ }
+
+ // QTBUG-54573
+ function test_modelReset() {
+ var control = comboBox.createObject(testCase, {model: resetmodel})
+ verify(control)
+ control.popup.open()
+
+ var listview = control.popup.contentItem
+ verify(listview)
+
+ waitForRendering(listview)
+ compare(listview.contentItem.children.length, resetmodel.count + 1) // + highlight item
+
+ resetmodel.clear()
+ resetmodel.append({text: "Fourth"})
+ resetmodel.append({text: "Fifth"})
+
+ waitForRendering(listview)
+ compare(listview.contentItem.children.length, resetmodel.count + 1) // + highlight item
+
+ control.destroy()
+ }
}