Labels

16/07/2009

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

-----------------------
Edit:

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:
#include

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()));
timer1->start(250);

MainWindow::timerEvent()
{
........
}

No comments:

Post a Comment