See the documentation of QCoreApplication::exec
:
We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function because on some platforms the QCoreApplication::exec() call may not return. For example, on Windows when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function after the QCoreApplication::exec() call.
You're using it incorrectly. It is not guaranteed that exec
will be terminated after windows are closed. You should use aboutToQuit
signal to stop other threads. If this signal is not emitted either, you need to call QApplication::quit()
explicitly when your window is closed.