如何使用QT设计秒表功能
导读:本文共1756字符,通常情况下阅读需要6分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 这篇“如何使用QT设计秒表功能”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“如何使用QT设计秒表功能”文章吧。设计目标1. 定时器开始2.复位从0开始计时3.记录--把记... ...
目录
(为您整理了一些要点),点击可以直达。
这篇“如何使用QT设计秒表功能”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“如何使用QT设计秒表功能”文章吧。
设计目标
1. 定时器开始
2.复位从0开始计时
3.记录--把记录的时间添加到QTextBrowser, append(时间)
4. QTime t(0,0,0) t = t.addMsec( number ) t.toString (“hh:mm:ss:zzz”)
定时器(QTimer)的使用
定时器---定时发送信号timeout
QTimer 定时器类
1.创建定时器类对象
QTimer mtimer;
2.把定时器信号与槽函数关联
connect(&mtimer, &QTimer::timeout, this, &TimerWin::on_outBt_clicked);
3.启动定时器
mtimer.start(1000);
4.停止定时器
mtimer.stop();
QT Creator组件布局
运行效果
源码
stopwatchwin.h
#ifndefSTOPWATCHWIN_H#defineSTOPWATCHWIN_H#include<QMainWindow>#include<QTime>#include<QTimer>namespaceUi{classStopwatchWin;}classStopwatchWin:publicQMainWindow{Q_OBJECTpublic:explicitStopwatchWin(QWidget*parent=nullptr);~StopwatchWin();voidfun_clicked();privateslots:voidon_pushButton_clicked();voidon_startBt_clicked();voidon_stopBtn_clicked();voidon_recordBtn_clicked();voidon_resertBt_clicked();private:Ui::StopwatchWin*ui;//QTimet;QTimet=QTime(0,0,0,0);QTimermtimer;};#endif//STOPWATCHWIN_H
stopwatchwin.cpp
#include"stopwatchwin.h"#include"ui_stopwatchwin.h"#include<QDebug>StopwatchWin::StopwatchWin(QWidget*parent):QMainWindow(parent),ui(newUi::StopwatchWin){ui->setupUi(this);//把定时器信号与槽函数关联connect(&mtimer,&QTimer::timeout,this,&StopwatchWin::fun_clicked);}StopwatchWin::~StopwatchWin(){deleteui;}voidStopwatchWin::fun_clicked(){QStringtim=t.toString("hh:mm:ss:zzz");t=t.addMSecs(10);ui->lcdNumber->display(tim);qDebug()<<"1111";}voidStopwatchWin::on_startBt_clicked(){qDebug()<<"启动定时器";mtimer.start(10);}voidStopwatchWin::on_stopBtn_clicked(){qDebug()<<"停止定时器";if(mtimer.isActive()){mtimer.stop();}}voidStopwatchWin::on_pushButton_clicked(){}voidStopwatchWin::on_recordBtn_clicked(){QStringtim=t.toString("hh:mm:ss:zzz");ui->textBrowser->append(tim);}voidStopwatchWin::on_resertBt_clicked(){t=QTime(0,0,0,0);}
main.cpp
#include"stopwatchwin.h"#include<QApplication>intmain(intargc,char*argv[]){QApplicationa(argc,argv);StopwatchWinw;w.show();returna.exec();}
以上就是关于“如何使用QT设计秒表功能”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
如何使用QT设计秒表功能的详细内容,希望对您有所帮助,信息来源于网络。