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:
parent
75ca70288c
commit
789d487cb0
@ -2191,10 +2191,9 @@ QString QComboBox::currentText() const
|
|||||||
Q_D(const QComboBox);
|
Q_D(const QComboBox);
|
||||||
if (d->lineEdit)
|
if (d->lineEdit)
|
||||||
return d->lineEdit->text();
|
return d->lineEdit->text();
|
||||||
else if (d->currentIndex.isValid())
|
if (d->currentIndex.isValid())
|
||||||
return d->itemText(d->currentIndex);
|
return d->itemText(d->currentIndex);
|
||||||
else
|
return {};
|
||||||
return d->placeholderText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -408,7 +408,7 @@ void tst_QComboBox::getSetCheck()
|
|||||||
obj1.clear();
|
obj1.clear();
|
||||||
obj1.setPlaceholderText(placeholderText);
|
obj1.setPlaceholderText(placeholderText);
|
||||||
obj1.addItems({"1", "2", "3", "4", "5"});
|
obj1.addItems({"1", "2", "3", "4", "5"});
|
||||||
QCOMPARE(obj1.currentText(), placeholderText);
|
QCOMPARE(obj1.currentText(), QString());
|
||||||
QCOMPARE(obj1.currentIndex(), -1);
|
QCOMPARE(obj1.currentIndex(), -1);
|
||||||
obj1.setPlaceholderText(QString()); // should not change anything
|
obj1.setPlaceholderText(QString()); // should not change anything
|
||||||
QCOMPARE(obj1.currentText(), "1");
|
QCOMPARE(obj1.currentText(), "1");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user