At the request of small partners, make a small timer. The function is to start the timer from 00:00:00, click on pause to pause the timer, click Stop to stop the timing.
Interface such as, using the UI designer to drag directly. The pictures of the buttons and icons are all downloaded online. With the beauty of the 美图秀秀 to become transparent, it will look good.
The overall code is very easy, is to set a timer. The code is as follows:
Mainwindow.h
#ifndef Mainwindow_h#defineMainwindow_h#include<QMainWindow>#include<QDateTime>#include<QTimer>#include<QTime>#include<QPixmap>#include<QIcon>namespaceUi {classMainWindow;}classMainWindow: Publicqmainwindow{Q_object Public: ExplicitMainWindow (Qwidget *parent =0); ~MainWindow ();PrivateSlots:voidUpdateTime (); voidon_start_clicked (); voidon_stop_clicked ();Private: Ui::mainwindow*UI; Qtimer* TIMER;//Timer update time per secondQtime * TIMERECORD;//Recording Time BOOLIsstart;//whether the record has started timingQicon *Starticon; Qicon*Pauseicon; Qicon*Stopicon;};#endif //Mainwindow_h
Mainwindow.cpp
#include"mainwindow.h"#include"ui_mainwindow.h"Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent), UI (NewUi::mainwindow) {UI->SETUPUI ( This); Setwindowicon (Qicon (":/icon.png")); Setwindowtitle ("Timerz"); //setwindowflags (qt::framelesswindowhint);Isstart =false;//Initial to not yet timedTimer =NewQtimer;//Initialize TimerTimerecord =NewQtime (0,0,0);//Initialization TimeUI->timer->setdigitcount (8); UI->timer->Setsegmentstyle (Qlcdnumber::flat); UI->timer->display (Timerecord->tostring ("Hh:mm:ss")); Qpixmap Pixstart (":/start.png"); Starticon=NewQicon (Pixstart); Qpixmap Pixpause (":/pause.png"); Pauseicon=NewQicon (Pixpause); Qpixmap Pixstop (":/stop.png"); Stopicon=NewQicon (pixstop); UI->start->seticon (*Starticon); UI->start->Show (); UI->stop->seticon (*Stopicon); UI->stop->Show (); Connect (timeout ()), Timer,signal This, SLOT (UpdateTime ()));} MainWindow::~MainWindow () {DeleteUI;}voidMainwindow::updatetime () {*timerecord = Timerecord->addsecs (1); UI->timer->display (Timerecord->tostring ("Hh:mm:ss"));}voidmainwindow::on_start_clicked () {if(!isstart)//start timing not yet started{UI->start->seticonsize (Qsize ( -, -)); UI->start->seticon (*Pauseicon); UI->start->Show (); Timer->start ( +); } Else //already started, paused{UI->start->seticon (*Starticon); UI->start->Show (); Timer-Stop (); } Isstart= !Isstart;}voidmainwindow::on_stop_clicked () {Timer->stop ();//Timer StopTimerecord->sethms (0,0,0);//time set to 0Ui->timer->display (Timerecord->tostring ("Hh:mm:ss"));//Show 00:00:00Isstart =false;}
Main.cpp hasn't changed.
" mainwindow.h " <QApplication>int main (intChar *argv[]) { qapplication a (argc, ARGV); MainWindow W; W.show (); return a.exec ();}
The specific difficulty is that at the time of release, click on the generated EXE always can not run. It turns out that all the dynamic link libraries needed to be copied into the Exe folder.
The next dllshow can show all the libraries used to run the program, and copy the libraries used. A processexplorer is also used, and it will look a little bit more.
Using dllshow will look like this:
With processexplorer like this:
"QT" timer maker