QFuture that can be cancelled and report progress

前端 未结 5 1017
终归单人心
终归单人心 2020-12-13 01:22

The QFuture class has methods such as cancel(), progressValue(), etc. These can apparently be monitored via a QFutureWatcher

5条回答
  •  失恋的感觉
    2020-12-13 01:32

    For a long running single task, QThread is probably your best bet. It doesn't have build-in progress reporting or canceling features so you will have to roll your own. But for simple progress update it's not that hard. To cancel the task, check for a flag that can be set from calling thread in your task's loop.

    One thing to note is if you override QThread::run() and put your task there, you can't emit signal from there since the QThread object is not created within the thread it runs in and you can't pull the QObject from the running thread. There is a good writeup on this issue.

提交回复
热议问题