PDA

View Full Version : QSqlRelationalTableModel editing probllem



davidovv
28th December 2011, 00:35
This is a very strange situation. The code is small and simple


QSqlRelationalTableModel *model ;
model = new QSqlRelationalTableModel();
model->setTable("InputLabels");
// model->setRelation(model->fieldIndex("label_id"), QSqlRelation("Labels", "id", "text"));
model->select();
ui->tableView->setModel(model);


when i run it like this i can edit my data directly in the tableView and post it with model->submitAll()
but if remove comment from setRelation line, every time i exit focus after editing data, the data in cell reverts to original value. column i edit is not the one with relation. So if i use setRelation i am unable to edit data in tableView. Am i missing something or it is "a bug".
anyone with similar problem?

I also wanted to make the relation column read only, but that is another story :)

davidovv
30th December 2011, 14:27
answering my own thread
the problem was that the table had no primary key,
i still think that QSqlRelationalTableModel should behave the same, and that this is some kind of BUG, or at least missing functionallity.
With setRelation, QSqlRelationalTableModel has more information about database than without setRelation.

thanks davidovv :)