qt 定时器
定时器
头文件添加:
QTimer m_timerTime;//时间定时器,显示时间 public slots: void SlotTimerTime();
构造函数中添加:
connect(&m_timerTime, SIGNAL(timeout()), this, SLOT(SlotTimerTime())); //connect(&m_timerTime, &QTimer::timeout, this, &TitleBarTop::SlotTimerTime); m_timerTime.start(1000);
槽函数:
SlotTimerTime() { QDateTime dt = QDateTime::currentDateTime(); QString time = dt.toString("hh:mm:ss"); ui->lblTime->setText(time); }