This should be simple, but I can't see how to do it.
From the mainwiindow of the application, I create a QSqlTableModel and QTableView and show the view. It pops up in a nice separate window.

Qt Code:
  1. void MainWindow::showLog(QString fileName) {
  2. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  3. QString logTitle = fileName.mid(fileName.lastIndexOf("/")+1,(fileName.indexOf(".")-4)-(fileName.lastIndexOf("/")+1));
  4. QString logName = logTitle + "_log.sqlite";
  5. db.setDatabaseName(logName);
  6. db.open();
  7. model->setTable("log");
  8. model->select();
  9.  
  10. QTableView *view = new QTableView;
  11. view->setModel(model);
  12. view->setWindowTitle(logTitle);
  13. view->setMinimumSize(1200,100);
  14. view->move(35,80);
  15. view->setSortingEnabled(TRUE);
  16. view->show();
  17.  
  18. ControlDB ctrl;
  19. ctrl.setLastLog(logTitle);
  20. }
To copy to clipboard, switch view to plain text mode 

Then I insert into the database behind the model. This works ok. I can see the data in the database with a browser tool.
Qt Code:
  1. void MainWindow::writeLog() {
  2. ControlDB ctrl;
  3. QString logTitle = ctrl.getLastLog();
  4. QString logName = logTitle + "_log.sqlite";
  5. int newID = ctrl.getMaxID(logName) + 1;
  6.  
  7. QTime t(QTime::currentTime());
  8. QDate d(QDate::currentDate());
  9.  
  10. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  11. db.setDatabaseName(logName);
  12. db.open();
  13. QSqlQuery query;
  14. query.prepare("INSERT into log (id, call, sent, rcvd, date, timeon)VALUES(?, ?, ?, ?, ?, ?)");
  15. query.addBindValue(newID);
  16. query.addBindValue(ui->mwCall->text());
  17. query.addBindValue(ui->mwSent->text());
  18. query.addBindValue(ui->mwRcvd->text());
  19. query.addBindValue(d);
  20. query.addBindValue(t);
  21. query.exec();
  22. }
To copy to clipboard, switch view to plain text mode 

So, the question is, after the new data is inserted, how do I refresh the query in the model/view so it is updated?