我有同樣的情況是這樣的:stop thread started by qtconcurrent::runQtConcurrent ::運行如何停止後臺任務
我需要在封閉的closeEvent子線程(開始QtConcurrent ::運行)中的QMainWindow。 但我的孩子在使用線程函數的代碼從* .DLL:因爲所有我做的我不能老是用循環 - 被調用外部 DLL像
QFuture<void> = QtConcurrent::run(obj->useDllfunc_with_longTermJob());
當我關閉與x軸的應用按鈕我的GUI是關閉的,但第二個線程with_longTermJob()仍然工作,當完成時我有一個錯誤。 我知道有些決策是:
- 使用其他功能,如地圖()或別的東西與 QFuture.cancel /停止功能,而不是QtConcurrent :: run()的,但我只需要一個函數調用。 run()是我需要的。
- 或者使用QThread來代替Concurrent.But對我來說並不好。
什麼方法更簡單更好,我該如何實現呢?有沒有我不列出的方法? 您能否提供小代碼樣本以供決定。謝謝!
http://stackoverflow.com/questions/32952474/non-blocking-worker-interrupt-file-copy?lq=1 – dtech