Qt QEventLoop CPU使用率达到最大值

时间:2016-01-26 14:13:28

标签: c++ multithreading qt qeventloop

每当我在等待线程完成后台工作时运行QEventLoop时,即使线程在其功能中进行了大量等待并且没有进行大量计算,CPU使用率也会上升到100%。它是加载CPU的事件循环。有没有办法配置QEventLoop以便更慢地运行并节省CPU?

以下是一个例子:

WorkerThread thread;
QEventLoop eventLoop;
QTimer threadTimer;

threadTimer.setSingleShot(true);
connect(&threadTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
connect(&thread, SIGNAL(finished()), &eventLoop, SLOT(quit()));

threadTimer.start(180000);
thread.start();
eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
if(threadTimer.isActive())
{
   threadTimer.stop();
}

0 个答案:

没有答案
相关问题