其他分享
首页 > 其他分享> > Qt-moveToThread应用

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 }

 

标签:moveToThread,Qt,thread,worker,应用,Test,public,onHandle
来源: https://www.cnblogs.com/fengye2021/p/15363380.html