QSqlTableModel::select() does not fetch newly created columns



  • I have created a QSqlTableModel object which I use in a QSqlTableView to present some data from a database. When I add a new column to the database, the select function from the QSqlTableModel does not include and show it in the table, unless I restart the application.

    I was thinking of deleting the QSqlTableModel and recreating it, so that it recognizes the new column, however, that does not seem like a nice solution. Is there a better way of solving this?



  • Did you signal the View that the model has been updated? If you change model information you should inform the View about it, so to redraw it's information.



  • @Jeroentjehome said:

    Did you signal the View that the model has been updated? If you change model information you should inform the View about it, so to redraw it's information.

    How would I do that? Besides, is that really necessary, since adding a new record to the model automatically updates the view as well?



  • Hi,
    The bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex & parent = QModelIndex())
    which class is inherited by the QSqlTableModel should handle the insert of new colums and update the view.
    Because it's virtual you need to implement it for your self.
    Never worked with SQL tables before, but would try this out.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.