16,240
社区成员
发帖
与我相关
我的任务
分享
Worker *worker;
QTimer timer;
worker->moveToThread(Threaddata);
connect(&timer,SIGNAL(timeout()),worker,SLOT(repeatResult()));
timer.stop();
QObject::killTimer: timers cannot be stopped from another thread
QObject::startTimer: timers cannot be started from another thread
后来就使用了信号槽来控制计时器的开始和停止
connect(this,SIGNAL(trigTimer()),&guitimer,SLOT(start()));
connect(this,SIGNAL(stopTimer()),&guitimer,SLOT(stop()));
而且在repeatResult函数里面加了
mutex->lock();
......
mutex->unlock();
这样子基本能解决问题。你说的信号量,我看了《C++ GUI Qt4》里的介绍,好像是用来解决生产者和消费者问题的,不知道该怎么用来解决我的这个问题,少侠能否不吝赐教?