I have implemented an Oracle database. I use Qt for the GUI of my application and as an interface for the db. Setting up the connection to my db and displaying tables in a QTableView works fine. Edit of all cells is generally natively supported using QSqlTableModel. However, Qt does not seem to consider any constraints defined by the database when the associated default ItemDelegate edits a cell.
Say I edit a cell which is a foreign key value, not only does Qt let me enter none key values, but submitting these changes queries the db to perform an update. This obviously will not work, due to set constraints. Now, I get how it might be a bit too much to ask, to expect the default ItemDelegate for my view to check for valid values on edit.
The real problem occurs when I submit an unsupported value. The view still applies the value change, suggesting the edit is valid. No error is handled, nor is an error message delivered. From there on the view will not allow edits on some rows, until I revert the change to value that obeys my constraints.
I find it hard to believe, that I would have to setup my own itemDelegate, to validate value changes against constraints in the db.
Since I expect whoever is able to answer this post, knows how to set up the connection, I'll brake down the code a bit:
bool driverSuccess = validDriver(driver);
if(driverSuccess) {
_db = QSqlDatabase::addDatabase(driver);
_db.setHostName(host);
_db.setDatabaseName(dbName);
_db.setPort(port);
_db.setUserName(user);
_db.setPassword(pwd);
_db.open();
//... validate connection
}
// setup table model and connect to view
QSqlRelationalTableModel* model = new QSqlRelationalTableModel;
model->setTable(tableName);
model->select()
QTableView* table_view = new QTableView(0);
table_view->setModel(model);
//...
_db.close()
I'd appreciate any help. Thanks!