Stop Thread started by QtConcurrent::run?

后端 未结 2 706
清酒与你
清酒与你 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:26

    From the documentation of QtConcurrent::run:

    Note that the QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.

    What you could do is have a button press set a boolean flag in your main window and build your infinite loop like this:

    _aborted = false;
    
    forever    // Qt syntax for "while( 1 )"
    {
        if( _aborted ) return;
    
        // do your actual work here
    }
    

提交回复
热议问题