PDA

View Full Version : how to select QComboBox option which matches a QString contents



Channareddy
21st June 2011, 06:37
hi,
I have a problem in setting the desired option from the QComboBox.I have QComboBox with 9 drop down options.I am reading a string(which matches one of the options in drop down list) from a .csv file.Now i want the option present in the String to be displayed in the QComboBox.Please help me in achieving this ASAP.I went through docs but i am not getting it.

Thanks..

pkj
21st June 2011, 07:06
Ok from what I understand is that you want to load the contents from .csv to QComboBox.
1. Use QString::split function to get a QStringList of strings in .csv . More complicated options if required can be provided by QRegExp.
2. Load the QStringList to QComboBox::addItems()

Channareddy
21st June 2011, 07:33
u r partially correct.But the thing is i have a QComboBox with 9 options e.g Cadres like HR,SE.....i have stored particular cadre for particular user in file along with other details so when i want to see or edit his/her details then i need to display that file cadre into QComboxBox i.e it should show the cadre selected from file as currentItem/at currentIndex in QComboBox along with other 8 options.So that i can edit or retain same cadre from the QComboBox.
For that i am using a QString for storing cadre from file.Now i want to set that cadre to QComboBox.I think u got my problem now.

pkj
21st June 2011, 07:34
If you already have QComboBox populated and want to set index based on string matching use:
1. QComboBox::findText() to find index of string.
2. QComboBox::setCurrentIndex to set appropriated index.

Channareddy
21st June 2011, 13:05
Thank you pkj.. i got it solved...:)