說明:QtConcurrent 的線程函數啟動方式略述。
1) 全局函數或靜態函 ,作為線程函數
1 void threadFunc() 2 { 3 //...add
4 } 5 QtConcurrent::run(threadFunc);
2) 類成員函數作為線程函數
1 class worker 2 { 3 public: 5 Worker(); 7 ~Worker(); 9 void threadFunc(); 10 void start(); 11 }; 13 void worker::threadFunc() 14 { 15 //... add 16 } 18 void worker::start() 19 { 20 QtConcurrent::run(this,&worker::threadFunc); 21 }
3) 結構體函數作為線程函數
1 sturct worker 2 { 3 int ID; 4 void worker::threadFunc() 5 { 6 //... add
7 } 8 };//end
9
10 worker work; 11 QtConcurrent::run(&work,&worker::threadFunc);
補充:QtConcurrent默認使用全局線程池,經實測(CPU:i3-4150)雙核四線程處理器,
開啟的最大線程數即為4;