In Qt, I can get the selected text
of a QComboBox
by using the combobox->currentText()
method. How can I get the selected value
?
I searched for help but I couldn't find a method currentData()
which I expected to find. I could only find combobox->currentIndex()
Is there a smarter way to do it other than combobox->itemData(combobox->currentIndex())
?
Update: This is no longer necessary as of Qt 5. A currentData()
method has been added http://doc.qt.io/qt-5/qcombobox.html#currentData-prop
A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space. A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.
It seems you need to do combobox->itemData(combobox->currentIndex())
if you want to get the current data of the QComboBox.
If you are using your own class derived from QComboBox, you can add a currentData()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With