1、基本使用
①在.h中先声明定时器事件,该事件继承自QObject
virtual void timeEvent(QTimerEvent *event);
②重写定时器事件
void MyWin3::StartTimer(){
m_timerId = startTimer(500);
}
void MyWin3::timerEvent(QTimerEvent *event) {
if (event->timerId() == m_timerId) {
QTime now = QTime::currentTime();
QString time = now.toString("HH:mm:ss");
ui.timeLabel->setText(time);
}
}
③销毁定时器
killTimer(m_timerId);