现象:
创建了两个子线程和两个工作任务类,并且将工作任务通过moveToThread转移到了子线程。
发现子线程和主线程是并行的,但是两个子线程却是串行的。按理说两个子线程和主线程都应该是并行的才对.
有问题的代码:
LOG(INFO) <<"Proc Left";
QThread*pWorkerThread = new QThread;
CEyeProcWork *pWork = new CEyeProcWork(this);
pWork->Init(strSrcNameL, strMaskNameL, strIrisNameL);
pWork->moveToThread(pWorkerThread);
QObject::connect(pWorkerThread, &QThread::started, pWork, &CEyeProcWork::doWorking, Qt::QueuedConnection);
pWorkerThread->start();
LOG(INFO) <<"Proc Right";
QThread*pWorkerThread2 = new QThread;
CEyeProcWork *pWork2 = new CEyeProcWork(this);
pWork2->Init(strSrcNameR, strMaskNameR, strIrisNameR);
pWork2->moveToThread(pWorkerThread2);
QObject::connect(pWorkerThread2, &QThread::started, pWork2, &CEyeProcWork::doWorking, Qt::QueuedConnection);
pWorkerThread2->start();
没问题的代码
LOG(INFO) <<"Proc Left";
QThread*pWorkerThread = new QThread;
CEyeProcWork *pWork = new CEyeProcWork();
pWork->Init(strSrcNameL, strMaskNameL, strIrisNameL);
pWork->moveToThread(pWorkerThread);
QObject::connect(pWorkerThread, &QThread::started, pWork, &CEyeProcWork::doWorking, Qt::QueuedConnection);
pWorkerThread->start();
LOG(INFO) <<"Proc Right";
QThread*pWorkerThread2 = new QThread;
CEyeProcWork *pWork2 = new CEyeProcWork();
pWork2->Init(strSrcNameR, strMaskNameR, strIrisNameR);
pWork2->moveToThread(pWorkerThread2);
QObject::connect(pWorkerThread2, &QThread::started, pWork2, &CEyeProcWork::doWorking, Qt::QueuedConnection);
pWorkerThread2->start();
问题就出在给工作对象添加了一个父类this指针。