Timer event


#include “qtimer.h”

in main.cpp main function add:
startTimer(100) //start timer, and timer event triggered every 100 ms

PS: it is a little bit strange here. i don't need to declare a QTimer class. i may find the reason in the future since i am a just beginner in Qt

in main.h add:
void timerEvent(QTimerEvent *event);

in main.cpp add:
void MainWindow::timerEvent(QTimerEvent *event


my concern was right, my previous code was wrong. i actually calling the system timer event, not the timer which i created.

here is the correct code:

in main.h add:

QTimer *timer1;
void timerEvent();

in main.cpp add:

timer1 = new QTimer(this); // start timer event
connect(timer1, SIGNAL(timeout()), this, SLOT(timerEvent()));


No comments:

Post a Comment