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

Is Thread stop right?



  • Eg1:
    at MainForm:

    MainForm()
    {
        this->thread = NULL;
    }
    
    void start()
    {
        Worker *worker = new Worker();
        this->thread = new QThread();
        worker->moveToThread(thread);
        connect(thread, SIGNAL(started()), worker, SLOT(process()));
    }
    
    void stop()
    {
       if (thread != NULL)
        {
            if(thread->isRunning())
            {
                th_getBuild->quit();
                th_getBuild->wait();
                th_getBuild->deleteLater();
            }
        }
    }
    

    Eg2: It is Eg1. But class Worker has a method stop() (maybe slot), it also called immediately.
    stop() method rewrited:

    void stop()
    {
       if (thread != NULL)
        {
            if(thread->isRunning())
            {
                worker->stop();
                th_getBuild->quit();
                th_getBuild->wait();
                th_getBuild->deleteLater();
            }
        }
    }
    

    has it any problem?



  • @Kien-Bui
    What is th_getBuild, and what relationship if any does it have to thread?


Log in to reply