[Solved] The most accurate timer qt C++

Run a QTimer on a separate QThread which doesn’t do anything else. If you’re running the timer on an already busy thread the timeout events may not come on time or not at all. Make a worker class e.g. “PingPacketWorker”, implement a slot that does pinging. Make a QThread. Connect your QTimer and PingPacketWorker signal/slots. … Read more

[Solved] how to stop the Qtimer upon a condition

Declare the QTimer as a member in you class h file: class Ball: public QObject, public QGraphicsRectItem{ { Q_OBJECT public: // constructor Ball(QGraphicsItem* parent=Q_NULLPTR); // control your timer void start(); void stop(); … private: QTimer * m_poTimer; } Initiate the timer object in your constractor cpp file: Ball::Ball(QGraphicsItem* parent) : QGraphicsItem(parent) { m_poTimer = new … Read more