Multithreading – you can cancel qfuture and report progress
The qfuture class has some methods, such as cancel(), progressvalue(), and so on These can be monitored by qfuturewatcher However, the document reading of qtcurrent:: run():
I can't see what method can actually create a cancelable qfuture and report the progress of a long-running operation (it seems that qtcurrent:: Map () and similar functions can, but I only have a single, long-running method.)
(for those familiar with. Net, it is similar to the backgroundworker class.)
What options are available?
Solution
Qthread may be your best choice for a single task running for a long time It has no built - in progress report or cancel function, so you have to scroll by yourself But for simple progress updates, this is not very difficult To cancel the task, check the flag that can be invoked from the task loop.
It should be noted that if you rewrite qthread:: run() and put your task there, you can't send a signal because the qthread object is not created in the thread it runs, and you can't remove the QObject from the running thread This issue has a good writing