Qt QTimer定时器相关

时间:2022-08-24 00:11:33
1.创建QTimer类对象
#------------.h----------# QTimer *m_Timer; //定时器对象 #-------------.cpp-------# m_Timer = new QTimer(this); connect(m_Timer,&QTimer::timeout, [=]() { static int n = 0; n++; ui->lcdNumber->display(n); } );
2.通过timerEvent事件方法
#---------------.h-----------# protected: void timerEvent(QTimerEvent *event); private: int m_time_int; #---------------.cpp----------# m_time_int = this->startTimer(1000); void Widget::timerEvent(QTimerEvent *event) { if(event->timerId() == m_time_int) { static int i = 0; i++; ui->lcdNumber->display(i); } }