欢迎来到天天文库
浏览记录
ID:40753830
大小:72.00 KB
页数:4页
时间:2019-08-07
《QT倒计时器与进度条》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、效果图:源代码:main.cpp#include#include"mainwindow.h"intmain(intargc,char*argv[]){QApplicationa(argc,argv);MainWindoww;w.show();returna.exec();}Mainwindow.h#ifndefMAINWINDOW_H#defineMAINWINDOW_H#include#include#include#include#include
2、#includenamespaceUi{classMainWindow;}classMainWindow:publicQMainWindow{Q_OBJECTpublic:MainWindow(QWidget*parent=0);~MainWindow();protected:voidchangeEvent(QEvent*e);private:Ui::MainWindow*ui;boolm_BStop;intm_nPause;QTimer*myTimer;QDateTimeCurDate;privateslots:voidon_StopLCDB
3、tn_clicked();voidon_StartLCDBtn_clicked();voidon_StartBtn_clicked();voidShowTimer();};#endif//MAINWINDOW_HMainwindow.cpp#include"mainwindow.h"#include"ui_mainwindow.h"MainWindow::MainWindow(QWidget*parent):QMainWindow(parent),ui(newUi::MainWindow){ui->setupUi(this);m_BStop=false;m_nPause=0;myTim
4、er=newQTimer(this);connect(myTimer,SIGNAL(timeout()),this,SLOT(ShowTimer()));}MainWindow::~MainWindow(){deleteui;}voidMainWindow::changeEvent(QEvent*e){QMainWindow::changeEvent(e);switch(e->type()){caseQEvent::LanguageChange:ui->retranslateUi(this);break;default:break;}}voidMainWindow::on_StartB
5、tn_clicked(){boolok=true;intnum=100000;intbegin=m_nPause;ui->progressBar->setRange(0,num);for(inti=begin;i<=num;i++){if(!m_BStop){ui->progressBar->setValue(i);m_nPause=i;}else{ui->progressBar->setValue(i);m_BStop=true;}}QMessageBox::information(this,"CopyFile","Finish",QMessageBox::Ok,QMessageBo
6、x::Ok);}voidMainWindow::on_StartLCDBtn_clicked(){CurDate=QDateTime::currentDateTime();myTimer->start(1000);}voidMainWindow::ShowTimer(){intwyy=31-CurDate.secsTo(QDateTime::currentDateTime());if(wyy>=0){ui->lcdNumber->display(wyy);}else{on_StartBtn_clicked();myTimer->stop();}}voidMainWindow::on_S
7、topLCDBtn_clicked(){myTimer->stop();}
此文档下载收益归作者所有