QTableView don’t refresh with QSqlTableModel
I’m using QSqlTableModel with QTableView and I have a problem when try insert datas. QTableView don’t refresh. I test insertRow() with setData(), setRecord(), insertRecord(), submitAll(), and nothing.
I try with QSqlQuery::exec and return true, but de rowCount() return 0.
I have 4 tables in my DB:
QSqlTableModel model(0, db);
and nothing....somebody Help me. Thanks
You should try to provide code that will compile and demonstrates the problem. There's no QSqlTablemodel::insertRecord() that accepts a single value for example.
Here are some questions that might help you isolate the problem:
- Is the database connection is successfully opened? Did you check?
- Does a table called "student" exist in the database?
- Is dataStudentRecord a QSqlRecord that matches this model?
- QSqlTableModel::insertRow(), QSqlTableModel::setData(), QSqlTableModel::setRecord() and QSqlTableModel::submitAll() all return a value, did you check it?
- Are you sure your record is actually insertable and inserted? Does it violate database check or referential integrity constraints?
- When it fails, did you check the result of QSqlTableModel::lastError()?
Updating the table other than through the model, i.e. by executing a QSqlQuery separately, will not update the view or model unless you reset the model.