实例:
#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"))); }