Problem with hidden QMainWindow: application crashes after QMessageBox is displayed

The issue seems to be the following: When the dialog box is closed, the application thinks that there are no more windows open (setQuitOnLastWindowClosed refers to visible top-level windows), so it quits. The destructor of your window is not called because you never delete the object!

This should print out the message:

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);
  MainWindow* window = new MainWindow();
  window->show();
  int ret = app.exec();
  delete window;
  return ret;
}

Alternatively you can set the application as the window's parent


I'm not sure, but I think when QMessageBox has closed it is trying to return focus to his parent (Your MainWindow) witch is hidden. This operation fails, and system is throwing an exception.