aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp6
-rw-r--r--tests/auto/controls/data/tst_combobox.qml10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index e10a8b48..766cabe8 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -154,7 +154,7 @@ class QQuickComboBoxPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickComboBox)
public:
- QQuickComboBoxPrivate() : pressed(false), ownModel(false), hasDisplayText(false),
+ QQuickComboBoxPrivate() : pressed(false), ownModel(false), hasDisplayText(false), hasCurrentIndex(false),
highlightedIndex(-1), currentIndex(-1), delegateModel(nullptr),
delegate(nullptr), popup(nullptr) { }
@@ -177,6 +177,7 @@ public:
bool pressed;
bool ownModel;
bool hasDisplayText;
+ bool hasCurrentIndex;
int highlightedIndex;
int currentIndex;
QVariant model;
@@ -479,6 +480,7 @@ int QQuickComboBox::currentIndex() const
void QQuickComboBox::setCurrentIndex(int index)
{
Q_D(QQuickComboBox);
+ d->hasCurrentIndex = true;
if (d->currentIndex == index)
return;
@@ -857,7 +859,7 @@ void QQuickComboBox::componentComplete()
static_cast<QQmlDelegateModel *>(d->delegateModel)->componentComplete();
if (count() > 0) {
- if (d->currentIndex == -1)
+ if (!d->hasCurrentIndex && d->currentIndex == -1)
setCurrentIndex(0);
else
d->updateCurrentText();
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index ef46172f..c400d912 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -792,4 +792,14 @@ TestCase {
loader.destroy()
}
+
+ // QTBUG-52615
+ function test_currentIndex() {
+ var control = comboBox.createObject(testCase, {currentIndex: -1, model: 3})
+ verify(control)
+
+ compare(control.currentIndex, -1)
+
+ control.destroy()
+ }
}