Galen
16th April 2010, 04:34
edit: sorry, figured this one out so I'm changing the topic. I'd like to be able to stop and start this qtimer from within the timeoutHandler slot, but doing so gives errors about killing a timer from a different thread. The code below is just an example and in the real deal it would check a shared variable (modified by the parent) for a pause request, then use QMutex and QWaitCondition to control the pause. Does this sound like something that should even be possible in the first place? I've gotten around this by having the parent control the QTimer externally, but I'd rather all the load be in the child thread.
QObject::killTimer: timers cannot be stopped from another thread"
QOBject::startTimer: timers cannot be started from another thread"
void ThreadWatcher2::run() {
updateTimer = new QTimer();
QSignalMapper signalMapper;
for (int i=0; i<6; i++) {
connect(thread[i], SIGNAL(finished()), &signalMapper, SLOT(map()));
signalMapper.setMapping(thread[i], i); }
connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
updateTimer->start(10);
QThread::exec();
}
void ThreadWatcher2::timeoutHandler() {
for (int i=0; i<6; i++)
window[i]->update();
updateTimer->stop();
updateTimer->start(10);
if (threadsLeft==0)
QThread::exit(0);
}
void ThreadWatcher2::finishedHandler(int t) {
threadsLeft--;
QTextStream cout(stdout, QIODevice::WriteOnly);
cout << "t: " << t << endl;
}
QObject::killTimer: timers cannot be stopped from another thread"
QOBject::startTimer: timers cannot be started from another thread"
void ThreadWatcher2::run() {
updateTimer = new QTimer();
QSignalMapper signalMapper;
for (int i=0; i<6; i++) {
connect(thread[i], SIGNAL(finished()), &signalMapper, SLOT(map()));
signalMapper.setMapping(thread[i], i); }
connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
updateTimer->start(10);
QThread::exec();
}
void ThreadWatcher2::timeoutHandler() {
for (int i=0; i<6; i++)
window[i]->update();
updateTimer->stop();
updateTimer->start(10);
if (threadsLeft==0)
QThread::exit(0);
}
void ThreadWatcher2::finishedHandler(int t) {
threadsLeft--;
QTextStream cout(stdout, QIODevice::WriteOnly);
cout << "t: " << t << endl;
}