如何使用QT设计秒表功能(qt,开发技术)

时间:2024-05-04 06:40:02 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

这篇“如何使用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组件布局

如何使用QT设计秒表功能

运行效果

如何使用QT设计秒表功能

源码

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设计秒表功能的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Qt实现简易秒表设计的代码怎么写下一篇:

27 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18