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>
This commit is contained in:
Wang ChunLin 2020-09-22 14:57:26 +08:00
parent 75ca70288c
commit 789d487cb0
2 changed files with 3 additions and 4 deletions

View File

@ -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 {};
}
/*!

View File

@ -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");