我正在使用一个库,我需要调用一个触发函数来启动一些处理(启动一个执行该工作的线程)并立即返回。然后,当处理完成时,会发出一个信号。
这需要根据不同的参数定期进行。由于在处理过程中不能对触发函数进行其他调用,因此我需要以某种方式对它们进行排队。我考虑过使用 QEventLoop (“循环”),但到目前为止还没有运气。
请看这段代码:
test::test()
{
connect(&timer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(&timer2, SIGNAL(timeout()), this, SLOT(timer2Slot()));
connect(&library, SIGNAL(processingFinished()), &loop, SLOT(quit()));
timer.setInterval(2000);
timer.start();
timer2.setInterval(4000);
timer2.start();
}
void test::timerSlot()
{
loop.exec();
startProcessing(some_parameters);
}
void test::timer2Slot()
{
loop.exec();
startProcessing(some_other_parameters);
}
问题是在处理过程中调用 loop.exec() 时,我收到以下消息:
QEventLoop::exec: instance xxxxxx has already called exec()
做我想做的事情的正确方法是什么?
提前致谢。