Unresolved timer events
-
A mini sample file
main.cpp
:@ #include <iostream>
#include <QCoreApplication>class MyApp : public QCoreApplication { private: int m_idtimer; public: MyApp(int nargs, char* argc[]) : QCoreApplication(nargs, argc) { m_idtimer = startTimer(3000); // 3 segs. } protected: void timerEvent(QTimerEvent* e) { char c = '\0'; std::cout << "timerEvent" << std::endl; std::cin >> c; if (c == 'q') { killTimer(m_idtimer); quit(); } } }; int main(int nargs, char* argc[]) { MyApp app(nargs, argc); return app.exec(); }@
Extra mini
Makefile
:@ LDFLAGS = -I/usr/include/qt4 -I/usr/include/qt4/QtCore
LDLIBS = -lQtCore@Compiling and execution:
@ $ make main
g++ -I/usr/include/qt4/QtCore main.cpp -lQtCore -o main
$ ./main
timerEvent
1
timerEvent
2
timerEvent
3
timerEvent
q
$@Ok and then, my question. I've made this sample with the purpose of testing if timer events are accumulative.
When I executing the
main
program, the next occurs:the first
timerEvent
message is shown after 3 seconds, andtimerEvent()
waits a character.I press
1
inmediatly.3 seconds later, the second
timerEvent
message appear (as expected).I wait some seconds (15 or more) and I press
2
The third message is shown immediatly (one timer event accumulated).
I press
3
immediatly.And 3 seconds later the fourth message appear (no more timer events accumulated).
I press
q
and the program ends.Question: Why aren there no more timer events accumulated? Does this behaviour depend on the platform?
PD: My Qt version is 4.8, my SO Ubuntu 13.04, and my kernel (linux) 3.8.0-19-generic. The running graphic system is Gnome 3.
-
Yes, this behavior is platform dependent.