QTableView field (related to other db table) does not get refreshed
-
The articlesTable (a QTableView) displays data from db table 'articles'.
The field 'positions' is related to table 'positions'.
The code:// Create the data model for articles: model = new QSqlRelationalTableModel(); model->setEditStrategy(QSqlTableModel:: OnFieldChange); model->setTable("articles"); model->select(); // Remember the indexes of the columns: positionIdx = model->fieldIndex("position"); // Set the relations to the database table 'positions': model->setRelation(positionIdx, QSqlRelation("positions", "id", "name")); // articlesTable is a QTableView, set it's model ui.articlesTable->setModel(model);
The problem: -I add a new record in database table 'positions' -I call model->select() (to refresh articlesTable) -the new record is not displayed in the combo box of field 'positions' I must close the form and reopen it in order for this field to display the new record. How can I fix this?