I created one dialog that is used only to bindValues
in a SQL database,
and I can save every new record sucessfully. The problem is that I've got another dialog with QSQlTableModel
that only shows the information from the database. Every time I make a new record I must close the program and run it again to see the changes in the ShowInformationDialog()
.
Do you know some way such that I don't need to close the program to update the information in my ShowInformationDialog()
?
1 Answers
You can use select()
method of QSqlTableModel
class to repopulate the model with data from the database. Bound views get updated automatically. I suggest connecting a signal from wherever you update the data in the database (i.e. your dialog updating the SQL database) to custom slot in your ShowInformationDialog()
that calls the select()
of the QSqlTableModel
object. I assume you have a QMainWindow
object that is parent of both dialogues which would be most likely the best place to establish the connection.
Also since your ShowInformationDialog()
's model is only used for viewing the data consider using QSqlQueryModel
. If that is used then setQuery()
method should be used instead of select()
but otherwise (the connection of a signal to ShowInformationDialog()
's slot) it would be the same.

- 3,916
- 2
- 34
- 56