定时器的使用

来源:互联网 发布:软件实施工程师薪金 编辑:程序博客网 时间:2024/06/08 05:53

编程环境

 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);}

这里写图片描述

原创粉丝点击