Home > Blockchain >  How to exit QApplication from another thread?
How to exit QApplication from another thread?

Time:05-25

So the problem is that in any application sometimes the GUI might freeze. Regardless of why it has happened, I want to be able to terminate/exit/quit my application.
Is there any way to do it from another thread (in the same application instance)? Assume that the GUI event loop is frozen and stuck in a while(1); line for example!

What I've already tried:
Calling QCoreApplication::quit() on qApp from another thread, which doesn't work because the GUI event loop is blocked.
Calling QCoreApplication::exit() on qApp from another thread, which doesn't work because it says I can only call it from the GUI thread.

If it is not possible to do it from another thread, how would you suggest to exit the application, assuming the GUI thread is blocked?

CodePudding user response:

Do you want a hard or a graceful exit? For a super hard exit, that can't be blocked by shutdown handlers (destructors, functions registered with atexit) use the C standard function abort: https://en.cppreference.com/w/cpp/utility/program/abort

  • Related