
Originally Posted by
mclark
What\Who is deleting the QTimer?
Provided that the timer doesn't have a parent it has to be you or the timer is not deleted at all.
Why is the m_pTimer value valid immediately after exec() returns but invalid when isActive() is called?
Maybe you have a local variable somewhere that is named the same and it shadows the other variable?
Would it be better to handle the deletion of m_pTimer in response to the QThread::finished() signal?
No. If you create an object in run(), destroy it there. The timer won't timeout anyway after you return from exec() so there is no point in keeping it. I even suggest you change your run() a bit:
void ...:run(){
connect(&timer, SIGNAL(timeout()), this, SLOT(checkTimestamp()));
timer.start(5000);
exec();
// the timer will get deleted when run() returns
}
void ...:run(){
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(checkTimestamp()));
timer.start(5000);
exec();
// the timer will get deleted when run() returns
}
To copy to clipboard, switch view to plain text mode
By the way, I hope you realize the slot will be called in the context of the main thread and not the worker thread. What is the point in doing all that in a worker thread anyway? Does the thread do anything else besides running the timer?
Bookmarks