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?



  • @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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.