QtQtConcurrent 使用方式


說明: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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM