Setting CurrentIndex of comboBox with model
I have combobox with model like this
Code:
cityModel->setTable("cities"); // (city_id, city_name)
cityModel->select();
comboBox_city->setModel(cityModel);
comboBox_city->setModelColumn(1);
comboBox_city->setCurrentIndex(0);
I want to change current index of combobox to row of city_id has 15 value?
Please help me.
Following line doesnt work.
Code:
comboBox_city->setCurrentIndex(comboBox_city->findData(query.value(rec.indexOf("city_id"))) );
Re: Setting CurrentIndex of comboBox with model
How about:
Code:
for(int i=0;i<cityModel->rowCount();i++){
QModelIndex index
= cityModel
->index
(i, rec.
indexOf("city_id"));
if(index.data().toInt()==15){
comboBox_city->setCurrentIndex(i);
return;
}
}