QTimer定时器以及QTime获取时间

时间:2021-08-09 00:10:56

实例:


#include <QTime>
#include <QTimer>

{
    QTimer *myTimer;
    myTimer=new QTimer(this);
    myTimer->start(1000);
    connect(myTimer,SIGNAL(timeout()),this,SLOT(getDateTime()));
}


void MainWindow::getDateTime()
{
    ui->label_time->setText(QTime::currentTime().toString());
    ui->label_date->setText(QDate::currentDate().toString(tr("yyyy-MM-dd dddd")));
}