How to store current selection from QcomboBox in a Variable
Hi,
I'm using a UI i created using the QtDesigner with several Comboboxes in it and am wondering how to get the selected item in the combobox to store in a variable.
by this i mean the user selects an option in one of the comboboxes, i need to take the users selection (in my case a few of the options are Chiron,Cyclops,aesir) and then store the options they selected somewhere for me to use for calculations later with data i have read from a .xls file using xlrd.
looking around i have seen currentIndexChanged(int) to send a signal to a slot with the index of the option the user selected, however i am unsure of how to implement this to store into a variable or other container.
Thanks in Advance
-Angel
Re: How to store current selection from QcomboBox in a Variable
QComboBox::currentIndex() and QComboBox::currentText() give you the entry number and text respectively of the currently selected item in the combo box (if there is one). The signal you named tells you when that changes. So you want something like:
Code:
private:
int m_diety;
...
m_deity = ui->deityCombo->currentIndex();
// or
m_deity = ui.deityCombo->currentIndex();
// or
m_deity = deityCombo->currentIndex();
// depending on how you have incorporated the designer UI
Re: How to store current selection from QcomboBox in a Variable
as Chrish said,
use QComboBox::currentText() to get the stored text in QComboBox.
Quote:
by this i mean the user selects an option in one of the comboboxes, i need to take the users selection (in my case a few of the options are Chiron,Cyclops,aesir) and then store the options they selected somewhere for me to use for calculations later with data i have read from a .xls file using xlrd.
If u want to do some actions based on user selection,use activated(QString) signal
Quote:
void QComboBox::activated ( const QString & text ) [signal]
This signal is sent when the user chooses an item in the combobox. The item's text is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().
hope it helps
Bala