Set a QString data in a QSqlRelationalTableModel
-
wrote on 24 Apr 2014, 09:50 last edited by
Hi everybody !
I got a little problem with my model (and I think the problem would be the same with another kind of model).
I have a QString to write in my model.
For exemple, I have already some data in my model, got from a database. Here, a transportation (destination, product, vehicule). I added a column in this model and I want to write something (list of drivers related to this transport) in theses items. I have my QString with the good names etc, but I can't wite it in the model, the items stay withe, nothing written in it.I tried to use setData() but it doesn't seem to work :/
If somebody has an idea, it would be cool ^^
Thanks anyway for the attentions. -
wrote on 24 Apr 2014, 10:32 last edited by
Just asking the obvious, but are the flags for the column set to be editable in your model. The flags in the model determine the way the view handles different columns. If you want to make it fancy you could also add a delegate (QComboBox e.g.).
Then when you are finished editing the string the setData will be called. You have to store the data in your model yourself. -
wrote on 24 Apr 2014, 12:04 last edited by
@Qt::ItemFlags TableSql::flags(QModelIndex index)
{
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
if (index.column() == 4)
{
flags = Qt::ItemIsEditable;
return flags;
}
return QAbstractTableModel::flags(index);
}@I tried this on my model class, but nothing changed.
My call of setData() :
@modelGererTransports->setData(vueGererTransports->model()->index(ligne, 4), chauffeurs, Qt::EditRole);@Where modelGererTransports = TableSql (inhérits from QSqlRelationalTableModel), vueGererTransports = QTableView and chauffeurs = QString
-
wrote on 24 Apr 2014, 14:20 last edited by
Hi,
Maybe to solve this problem it's best to use a 'default' QTableView to display the data. That way you're able to pinpoint the problem. Maybe your view implementation is not correct, so the call to setData is wrong. When you use the default View it will all go in the normal way as it should. We can go from there.
Also, debug the flags and setData functions. Check out what happens. -
wrote on 29 Apr 2014, 08:46 last edited by
But, I'm using the "default" QTableView (with or without delegate) ^^"
I'll test with the Debug one more time.
1/5