答:
你写的程序有问题吧,根据qt官网进行说明的线程推荐使用方法,把qobject放置耗时函数,使用movetothread讲qobject放入线程,你的mask0,1,2都是qthread,然后你又进行movetothread操作。(这个我不知道会有什么错误,但不推荐这么做)
更改后代码如下,时间运行基本是一致的,不会有什么太大区别
QThread *aThread=new QThread(this);
QThread *bThread=new QThread(this);
QThread *cThread=new QThread(this);
A *a=new A;
B *b=new B;
C *c=new C;
a->moveToThread(aThread); //放入线程
b->moveToThread(bThread);
c->moveToThread(cThread);
aThread->start(); //线程启动后会一直运行,直到当前窗体被关闭或删除
bThread->start();
cThread->start();
connect(this,&Widget::sSendA,a,&A::function); //信号和槽绑定,确定什么时候进行执行
connect(this,&Widget::sSendB,b,&B::function);
connect(this,&Widget::sSendC,c,&C::function);
emit sSendA();
emit sSendB();
emit sSendC();
