Stop Thread started by QtConcurrent::run?

后端 未结 2 601
清酒与你
清酒与你 2021-01-12 14:48

Is it possible to stop a Thread by its associated QFuture Object ? Currently i\'ve been starting a video capturing process like this.

this->cameraThreadRe         


        
2条回答
  •  被撕碎了的回忆
    2021-01-12 15:13

    Why don't you create a boolean flag that you can test inside your capturing loop and when it is set, it jumps out and the thread exits?

    Something like:

    MainWindow::onCancelClick() // a slot
    {
        QMutexLocker locker(&cancelMutex);
        stopCapturing = true;
    }
    

    And then for your threaded function:

    MainWindow::startLiveCapturing()
    {
       forever
       {
    
           ...
           QMutexLocker locker(&cancelMutex);
           if (stopCapturing) break;
       }
    
    }
    

提交回复
热议问题