Qt-moveToThread应用

 1 class Test : public QObject
 2 {
 3     ...
 4     private:
 5         QThread* thread; //工作线程
 6         Worker* worker; //工作类
 7 };
 8 
 9 Test::Test()
10 {
11     thread = new QThread;
12     thread->start();
13     worker = new Worder;
14     worker->moveToThread(thead); //将耗时操作移到worker中处理
15     //与worker交互通过信号槽处理,而不是函数调用
16     connect(this, SIGNAL(sigStart()), worker, SLOT(onHandle()));
17 }
18 
19 class Worker : public QObject
20 {
21     ...
22     public slots:
23         void onHandle();
24     ....
25 }

 

上一篇:五十音小游戏中的前端知识


下一篇:负载均衡理论