4

I use QSqlQueryModel.setQuery() method to read data from two tables in a MYSQL database, and set the QSqlQueryModel object to a QTableView object.

For some reason I'll alter some data in the MYSQL tables by using QSqlQuery.exe() method, but the QSqlQueryModel and QTableView object can not be refreshed automaticly after the database changed. What is the best method to refresh/update the modle and view?

I have tried a QSqlQueryModel.setData() method to force the model data changed but it does not work, only by calling the QSqlQueryModel.setQuery() method again could work.But it is inefficiency parsing a new query just to refresh it. I just want to refresh a row or a value in the tableview.

asdzxc
  • 59
  • 5
  • 2
    `QSqlQueryModel` is not notified when any data in the database changes, so if you want it to update after calling `QSqlQuery.exec_()` method is setting the query back: `your_model.setQuery(your_model.query())` – eyllanesc Jun 27 '18 at 22:45

0 Answers0