View Full Version : Seg fault using QTimer on 64-Bit Ubuntu

2nd July 2009, 09:03
I have a problem with QTimer class. My application tries to maintain a sliding time window. It does process IP packets and uses the reception time of the packets to trigger some action every 5 seconds. The QTimer is used to maintain this action if there are no packets flowing in. That means that as long as there are packets arriving, I want to reset the QTimer so that it doesn't trigger.
Here is some sample code which outlines what I try to do. The run() method does represent the packet capture routine. Every second I do reset the timer, if IP packets arrive. Below in the sample to speed up things, I do invoke QTimer::start() for every iteration of the loop. On 32-Bit system this does finish after 2-3 seconds. On 64-Bit it does run forever, and after 2 day's of running in my app, I get a seg fault when a timer event expires.

CVO_Appl::CVO_Appl(QObject* parent)
: QThread(parent)
m_byExitCount = 0;
connect(&m_tTimer, SIGNAL(timeout()), this, SLOT(timeout()));
QTimer::singleShot(1000, this, SLOT(startThread()));
} // end method

} // end method

void CVO_Appl::startThread()
} // end method

// thread method
void CVO_Appl::run()
qDebug() << "Thread started";
for (int n = 0; n < 2000000; n++)
} // end for
qDebug() << "Thread stopped";
} // end method

// protected slot
void CVO_Appl::timeout()
qDebug() << QString("Timer timeout %1...").arg(m_byExitCount);
if (3 <= m_byExitCount)
} // end if
} // end method

Did anyone happen to see this as well? The core dump from the crash indicates that some timer is corrupt in the timerlist:

(gdb) bt
#0 0x00007fc407711527 in kill () from /lib/libc.so.6
#1 0x00000000004368cc in CVO_DaemonUtils::sigSegvHandler () at modules/config/cvo_daemonutils.cpp:390
#2 <signal handler called>
#3 QCoreApplication::notifyInternal (this=0x7fff119f6000, receiver=0x0, event=0x7fff119f5b60) at ../../include/QtCore/../../src/corelib/kernel/qobject.h:97
#4 0x00007fc40898409c in QTimerInfoList::activateTimers (this=0x6de130) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:193
#5 0x00007fc408984cd8 in QEventDispatcherUNIX::processEvents (this=0x6dc5b0, flags=@0x7fff119f5c20) at kernel/qeventdispatcher_unix.cpp:877
#6 0x00007fc408959625 in QEventLoop::processEvents (this=<value optimized out>, flags=@0x7fff119f5c60) at kernel/qeventloop.cpp:127
#7 0x00007fc40895977b in QEventLoop::exec (this=0x7fff119f5ca0, flags=@0x7fff119f5cb0) at kernel/qeventloop.cpp:178
#8 0x00007fc40895b729 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:827
#9 0x000000000040bd54 in main (argc=2, argv=0x7fff119f61e8) at main.cpp:437

Take a look at frame 3 above. The receiver is NULL which for sure did cause the crash. It seems that resetting the QTimer instance doesn't work right on 64-Bit platforms, because on 32-Bit this does never occur.