Hello everybody,
I'm using threads ... and I've got a question. I've subclassed QThread and when I call start() the function below is called. Great. Now I thought there's be two ways of doing things: the first way with a forever loop - it works fine; and the second way, with a timer. My question: How do I connect the timer properly?
update() is a func in 'this' i.e. MyClass where I do the work.
void MyClass::run()
{
//can do this ....
forever{
update();
sleep(3);//seconds
}
return;
//or could do this...
timer->setInterval(3000);
connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::QueuedConnection);
exec();
delete timer;
return;
}
void MyClass::run()
{
//can do this ....
forever{
update();
sleep(3);//seconds
}
return;
//or could do this...
QTimer* timer = new QTimer();
timer->setInterval(3000);
connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::QueuedConnection);
exec();
delete timer;
return;
}
To copy to clipboard, switch view to plain text mode
Bookmarks