Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the selected VALUE out of a QCombobox?

Tags:

qt

qcombobox

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

like image 471
sabbour Avatar asked Jan 13 '10 13:01

sabbour


People also ask

How do you use a QT combo box?

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.


1 Answers

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.

like image 116
Patrice Bernassola Avatar answered Oct 04 '22 13:10

Patrice Bernassola