Hi,
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.

Qt Code:
  1. CVO_Appl::CVO_Appl(QObject* parent)
  2. : QThread(parent)
  3. {
  4. m_byExitCount = 0;
  5. connect(&m_tTimer, SIGNAL(timeout()), this, SLOT(timeout()));
  6. m_tTimer.setInterval(5000);
  7. QTimer::singleShot(1000, this, SLOT(startThread()));
  8. } // end method
  9.  
  10. CVO_Appl::~CVO_Appl()
  11. {
  12. } // end method
  13.  
  14. void CVO_Appl::startThread()
  15. {
  16. m_tTimer.start();
  17. start();
  18. } // end method
  19.  
  20. // thread method
  21. void CVO_Appl::run()
  22. {
  23. qDebug() << "Thread started";
  24. for (int n = 0; n < 2000000; n++)
  25. {
  26. //m_tTimer.stop();
  27. //sleep(0);
  28. m_tTimer.start();
  29. } // end for
  30. qDebug() << "Thread stopped";
  31. } // end method
  32.  
  33. // protected slot
  34. void CVO_Appl::timeout()
  35. {
  36. m_byExitCount++;
  37. qDebug() << QString("Timer timeout %1...").arg(m_byExitCount);
  38. if (3 <= m_byExitCount)
  39. {
  40. } // end if
  41. } // end method
To copy to clipboard, switch view to plain text mode 

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

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

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.