代码实现
1 #include "timerun.h" 2 #include "ui_timerun.h" 3 4 timerun::timerun(QWidget *parent) : 5 QMainWindow(parent), 6 ui(new Ui::timerun), 7 mtime(0,0,0) 8 { 9 ui->setupUi(this); 10 connect(&timer,SIGNAL(timeout()),this,SLOT(update_show())); 11 } 12 void timerun::update_show() 13 { 14 mtime=mtime.addMSecs(1); 15 ui->label->setText(mtime.toString("hh:mm:ss:zzz")); 16 } 17 18 timerun::~timerun() 19 { 20 delete ui; 21 } 22 23 void timerun::on_btnstart_clicked() 24 { 25 timer.start(1); 26 } 27 28 void timerun::on_btnreset_clicked() 29 { 30 mtime.setHMS(0,0,0); 31 } 32 33 void timerun::on_btncount_clicked() 34 { 35 QString text=ui->label->text(); 36 ui->textBrowser->append(text); 37 } 38 39 void timerun::on_btnstop_clicked() 40 { 41 timer.stop(); 42 }