c++ - Set Value to QComboBox from QStringList -


in qt c++ gui application have qdialog window, there have few line-edits , setting display texts function call , settext(). have stored values in qstringlist (the qstringlist populating via database query) , setting text follows--

void mydialog::setdatatoform(qstringlist sl) {         ui->namelineedit->settext(sl[0]);         ui->emaillineedit->settext(sl[1]); } 

now, have qcombobox (gendercombobox). have set 3 items there - male, female, other (through qt creater layout editor). in qstringlist sl, value getting saved in sl[2].

how can set value of sl[2] qcombobox ???

you need set currentindex of qcombobox:

qstringlist genderlist; genderlist << "male" << female" << "other"; ui->gendercombobox->setcurrentindex(genderlist.indexof(sl[2])); 

while works example, suggest having @ samples provided in qt documentation (books example, sql widget mapper example) use models automatically populate widget contents based on sql tables.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -