// 实时更新时间, 设置时间间隔为1秒 QTimer* t_time = new QTimer(this); t_time->start(1000); connect(t_time, &QTimer::timeout, this, [=]() { QDateTime curTime = QDateTime::currentDateTime(); QString t_str = curTime.toString("yyyy-MM-dd hh:mm:ss"); ui.labMenuTime->setText(t_str); });