QT 对话框中动态显示时间
#include <QDateTime>
#include <QTimer>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
//显示时间
QTimer *timer = new QTimer(this);
displayTime();
connect(timer, SIGNAL(timeout()), this, SLOT(displayTime()));
timer->start(1000);
}
void Dialog::displayTime()
{
QDateTime dt;
QTime time;
QDate date;
dt.setTime(time.currentTime());
dt.setDate(date.currentDate());
QString currentDate = dt.toString("yyyy:MM:dd:hh:mm:ss");
ui->timeLabel_3->setText(currentDate);
}
声明:
private slots:
void displayTime();
时间: 2024-11-16 09:58:22