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);
}

 

posted @ 2022-10-27 17:32  阳光下的小土豆  阅读(59)  评论(0编辑  收藏  举报