编程环境
Qt Creator 3.0.0
Base on Qt 5.2.0 (MSVC 2010,32 bit)
//ui界面添加一个label控件
//mainwindow.h文件
private slots:
void TimerUpdata();
//mainwindow.c文件
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(TimerUpdata()));
timer->start(500);
}
void MainWindow::TimerUpdata()
{
QDateTime time = QDateTime::currentDateTime();
QString str_time = time.toString("yyyy-MM-dd hh:mm:ss");
ui->label->setText(str_time);
}