Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Killing all threads when closing program



  • Is there a way to kill all of the living threads when closing a program?



  • A signal that the application is shutting down, DTOR's, ThreadPools, WorkerThreads...

    Without knowing your setup and even if I did know... I'm just going to say err yes?

    Was there a specific case you were thinking / up against?


  • Moderators

    @michalt38
    hi, closing a program implicates the termination of all threads. Am I right in assuming, you want to stop all threads when the UI is closed?

    You can do a Signal/Slot connect when you create the thread to a complish that:

    QObject::connect(qApp, &QCoreApplication::aboutToQuit, myThread, &QThread::quit);
    

    or if your QThread is a class member you can handle that in the destructor:

    myClass::~myClass(){
        myThread->quit();
        myThread->wait();
    }
    

Log in to reply