Inconsistent / Inaccurate QTimer
-
I am using QTimer to generate a signal every second. The timer works well for a minute or two. However, after that time, the signal is not generated for up to 10 seconds.
The majority of the below timer code was taken from http://www.bogotobogo.com/Qt/Qt5_QTimer.php
Any suggestions as to why the timer is inconsistent?
Thank you in advance.
Hoyt
mytimer.h
#ifndef MYTIMER_H #define MYTIMER_H #include <QTimer> #include "animations.h" extern Animations animations; class MyTimer : public QObject { Q_OBJECT public: MyTimer(); QTimer *timer; public slots: void MyTimerSlot(); signals: void ping(int); }; #endif // MYTIMER_H
myTimer.cpp
#include "mytimer.h" #include <QDebug> MyTimer::MyTimer() { // create a timer timer = new QTimer(this); // setup signal and slot connect(timer, SIGNAL(timeout()), this, SLOT(MyTimerSlot())); timer->start(1000); // msec } void MyTimer::MyTimerSlot() { qDebug() << "Timer..."; emit ping(1); }
Edit: Added code tags -- @Wieland
-
Hi,
What happens in the slot connected to
ping
` ? -
The code for the timer is totally fine. The problem must be somewhere else. And as the code you posted doesn't contain anything more than the timer and that "ping" signal, said signal, resp. the slot / slots connected to it must be blamed.
-
@Wieland
My computer is currently rendering an animation that is using all cores at close to 100%. i will try my code again when the rendering is complete.
Thank you for your assistance.
Hoyt