summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang ChunLin <wangchunlin@uniontech.com>2020-09-22 14:57:26 +0800
committerWang ChunLin <wangchunlin@uniontech.com>2020-09-25 10:52:27 +0800
commit789d487cb0f4ef6f9d3e7c6ab5c5283dfe8dd350 (patch)
tree605c1fff1c8737811bcbc75cb7c1e8ebf11bab27
parent75ca70288c3f3e68b90ff8516f6f306691780f17 (diff)
fix QComboBox currentText return placeholderText
If it does not add item,the currentText should return empty string Fixes: QTBUG-86580 Pick-to: 5.15 Change-Id: I54c3a8b7ececfb1e62bcd7ac592feccaff3f8b48 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/widgets/qcombobox.cpp5
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp2
2 files changed, 3 insertions, 4 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 77ef69fa25..a03de6e7f2 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -2191,10 +2191,9 @@ QString QComboBox::currentText() const
Q_D(const QComboBox);
if (d->lineEdit)
return d->lineEdit->text();
- else if (d->currentIndex.isValid())
+ if (d->currentIndex.isValid())
return d->itemText(d->currentIndex);
- else
- return d->placeholderText;
+ return {};
}
/*!
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 2ceba99d91..c7d918fa6a 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -408,7 +408,7 @@ void tst_QComboBox::getSetCheck()
obj1.clear();
obj1.setPlaceholderText(placeholderText);
obj1.addItems({"1", "2", "3", "4", "5"});
- QCOMPARE(obj1.currentText(), placeholderText);
+ QCOMPARE(obj1.currentText(), QString());
QCOMPARE(obj1.currentIndex(), -1);
obj1.setPlaceholderText(QString()); // should not change anything
QCOMPARE(obj1.currentText(), "1");