Thank you! That was exactly what I was looking for. It just so happens that I stumbled upon a similar example right before I saw your post. It had suspend function to stop the timer, which is pretty neat. If anyone's interested:
class MyThreadObject
: public QObject {
MyThreadObject() {
connect( &myTimer, timeout(), this, onTimeOut());
}
slot onSuspendThread() {
myTimer.stop();
}
slot onResumeThread() {
myTimer.start(0);
}
private slot onTimeOut() {
// do a few comutation steps.
// Should return "quickly" to the event loop
}
}
slot MyThread:run() {
MyThreadObject threadObject; //=> the threadObject affinity is the thread
// here, connect the appropriate signals to the appropriate slots
threadObject.onResumeThread();
exec();
}
}
class MyThreadObject : public QObject {
QTimer myTimer;
MyThreadObject() {
connect( &myTimer, timeout(), this, onTimeOut());
}
slot onSuspendThread() {
myTimer.stop();
}
slot onResumeThread() {
myTimer.start(0);
}
private slot onTimeOut() {
// do a few comutation steps.
// Should return "quickly" to the event loop
}
}
class MyThread : public QThread {
slot MyThread:run() {
MyThreadObject threadObject; //=> the threadObject affinity is the thread
// here, connect the appropriate signals to the appropriate slots
threadObject.onResumeThread();
exec();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks