Thanks for the reply. I placed the timer deletion code in the run() method but after exec() returns, the m_pTimer member value indicates that the QTimer instance has been deleted. The end result, of course, is a crash in QTimer because the value is bad.
- What\Who is deleting the QTimer?
- Why is the m_pTimer value valid immediately after exec() returns but invalid when isActive() is called?
- Would it be better to handle the deletion of m_pTimer in response to the QThread::finished() signal?
m_pTimer BEFORE exec() 0x1d8fc48
m_pTimer AFTER exec() 0x1d8fc48
m_pTimer BEFORE isActive() 0xfeeefeee
void WatchDogThread::run( void )
{
connect( m_pTimer, SIGNAL( timeout() ), this, SLOT( checkTimestamp() ) );
m_pTimer->start( 5000 );
qDebug( "m_pTimer BEFORE exec() 0x%x", m_pTimer );
exec();
qDebug( "m_pTimer AFTER exec() 0x%x", m_pTimer );
if ( m_pTimer != NULL )
{
qDebug( "m_pTimer BEFORE isActive() 0x%x", m_pTimer );
if ( m_pTimer->isActive() ) //<-- CRASH
m_pTimer->stop();
delete m_pTimer;
}
}
void WatchDogThread::run( void )
{
m_pTimer = new QTimer();
connect( m_pTimer, SIGNAL( timeout() ), this, SLOT( checkTimestamp() ) );
m_pTimer->start( 5000 );
qDebug( "m_pTimer BEFORE exec() 0x%x", m_pTimer );
exec();
qDebug( "m_pTimer AFTER exec() 0x%x", m_pTimer );
if ( m_pTimer != NULL )
{
qDebug( "m_pTimer BEFORE isActive() 0x%x", m_pTimer );
if ( m_pTimer->isActive() ) //<-- CRASH
m_pTimer->stop();
delete m_pTimer;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks