I have a QCombobox wich model is a QSqlTableModel populated with a DataBase table:
Integer | String
=-=-=-=-=-=-=-=
|
=-=-=-=-=-=-=-=
0 | Normal
=-=-=-=-=-=-=-=
1 | Leve
=-=-=-=-=-=-=-=
2 | Moderado
=-=-=-=-=-=-=-=
3 | Severo
=-=-=-=-=-=-=-=
the combobox works finecombo.PNG
but when I try to set the value in combo acording with the database table, I use this code
void MyComboBox
::setValor(QVariant myValue
) {
QModelIndexList myFinded=this->model()->match(this->model()->index(0,0),Qt::DisplayRole,myValue,5,Qt::MatchFlags(Qt::MatchExactly || Qt::MatchWrap));
this->setCurrentIndex(myFinded[0].row());
}
void MyComboBox::setValor(QVariant myValue)
{
QModelIndexList myFinded=this->model()->match(this->model()->index(0,0),Qt::DisplayRole,myValue,5,Qt::MatchFlags(Qt::MatchExactly || Qt::MatchWrap));
this->setCurrentIndex(myFinded[0].row());
}
To copy to clipboard, switch view to plain text mode
When myValue is 1, myFinded has 1 Index (corresponding to row 2)
When myValue is 2, myFinded has 1 Index (corresponding to row 3)
and so on
but when myValue is 0, myFinded has 2 Index (corresponding to row 0 and 1)
I don't understand why. Is this a bug? Or am I doing something wrong
Bookmarks