qt中如何取得系统时间并让它动态的显示到label标签上?

2025-02-02 08:38:51
推荐回答(1个)
回答1:

¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥实现方法如下: 构造函数中加入: QTimer *timer = new QTimer(this); connect(timer,SINGAL(timeout()),this,SLOT(timer_deal_slot_function())); 槽函数这样写:(获取系统时间) QDateTime dateTime = QDateTime::currentDateTime(); int y=dateTime.date().year(); int m=dateTime.date().month(); int d=dateTime.date().day(); QString strTime=dateTime.time().toString(); ui->label->setText(strTime+" "+QString::number(y)+"/"+QString::number(m)+"/"+QString::number(d)); //显示时间格式为例如 12:24:33 2008/8/28 ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥