It looks like the problem is you're not allowed to call QApplication::quit()
or QApplication::exit()
until the QApplication event loop has actually started. The event loop gets started by QApplication::exec()
, so you're calling quit()
/exit()
too soon for it to have an effect.
You can fix this either by moving the quit()
/exit()
call so that it's in the event loop (e.g. by moving your MainWindow::start()
code to the QMainWindow::showEvent()
slot), or by changing your MainWindow::start()
to return a value, inspect that value in main
, and exit (without calling QApplication::exec()`) if it's a value that indicates your process should exit early.