PDA

View Full Version : Setting CurrentIndex of comboBox with model



musti
16th November 2007, 10:13
I have combobox with model like this

cityModel = new QSqlTableModel(this);
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.

comboBox_city->setCurrentIndex(comboBox_city->findData(query.value(rec.indexOf("city_id"))) );

wysota
16th November 2007, 12:06
How about:


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;
}
}