Is Thread stop right?
Unsolved
General and Desktop
-
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?