PDA

View Full Version : QSqlRelationalTableModel: QTableModel shows foreign key, not displayvalue after edit



Al_
2nd April 2011, 17:50
I use a QSqlRelationalTableModel and a QTableView as follows:

QSqlRelationalTableModel* tableModel = new QSqlRelationalTableModel(this, db);
tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
// tableModel->setEditStrategy(QSqlTableModel::OnFieldChange);
tableModel->setTable(QLatin1String("Table1"));
tableModel->setRelation(0, QSqlRelation(QLatin1String("Table2"), QLatin1String("Number"), QLatin1String("String")));
tableModel->select();
tableView->setModel(tableModel);
tableView->resizeColumnsToContents();
QSqlRelationalDelegate* delegate = new QSqlRelationalDelegate(tableView);
Q_ASSERT(delegate);
tableView->setItemDelegate(delegate);
When I manually edit a value in the first column (i.e., a foreign key) a combo box presents the display values of Table2. However, when I pick one of these values, the view displays the key instead of the display value until I submitAll(). Is this behaviour expected?
When I use Qt::OnFieldChange as edit strategy, then the view displays instantly the display value; presumably since the change is submitted automatically.