QThread will emit a finished signal when the QThread::run method is finished. Perhaps you have the wrong implementation of this.
The default implementation of the run method looks like this. It just calls another exec method.
void QThread::run() { (void) exec(); }
Implementing the exec method is a bit more complicated. Now I have simplified it.
int QThread::exec() { // ..... if (d->exited) { return d->returnCode; } // ...... QEventLoop eventLoop; int returnCode = eventLoop.exec(); return returnCode; }
Judging by the code, it can be completed in two cases. In the first case, if he has already left. Secondly, it enters the event loop and waits until exit() called.
As we can see now, your infinity flow cycle is here. So you need QThread::quit() equal to QThread::exit(0) .
PS Do not use terminate . This is dangerous.
source share