Ok, I'm stumped.
When I call openLog from the mainwindow menu, the existing model and view are deleted and replaced by the selected new ones. Works perfectly.
But, when I call openLog from a dialog via the mainwindow menu, to create and open a new database, it crashes when it tries to delete the current model and view.

Qt Code:
  1. void MainWindow::openLog(QString logName) {
  2. delete model; // existing
  3. delete view; // existing
  4.  
  5. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  6. db.setDatabaseName(logName + ".log.sqlite");
  7. db.open();
  8. model = new QSqlTableModel();
  9. view = new QTableView();
  10.  
  11. model->setTable("log");
  12. //etc ...
To copy to clipboard, switch view to plain text mode 

But... this crashes unless I comment out the delete model and delete view lines.

Qt Code:
  1. void NewLog::createLog() {
  2. QString log = m_ui->nlName->text();
  3.  
  4. MainWindow mw;
  5. mw.openLog(log);
  6. NewLog::close();
  7. }
To copy to clipboard, switch view to plain text mode