欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

QT設(shè)計(jì)秒表功能(跑步計(jì)時(shí)器)

 更新時(shí)間:2022年08月04日 12:58:41   作者:Jason~shen  
這篇文章主要為大家詳細(xì)介紹了QT設(shè)計(jì)秒表功能,跑步計(jì)時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了QT設(shè)計(jì)秒表功能的具體代碼,供大家參考,具體內(nèi)容如下

設(shè)計(jì)目標(biāo)

1. 定時(shí)器開(kāi)始

2.復(fù)位從0開(kāi)始計(jì)時(shí)

3.記錄--把記錄的時(shí)間添加到QTextBrowser, append(時(shí)間)

4. QTime t(0,0,0)   t = t.addMsec( number )  t.toString (“hh:mm:ss:zzz”)

定時(shí)器(QTimer)的使用

定時(shí)器---定時(shí)發(fā)送信號(hào)timeout
QTimer 定時(shí)器類(lèi)

1.創(chuàng)建定時(shí)器類(lèi)對(duì)象
QTimer mtimer;

2.把定時(shí)器信號(hào)與槽函數(shù)關(guān)聯(lián)
connect(&mtimer, &QTimer::timeout, this, &TimerWin::on_outBt_clicked);

3.啟動(dòng)定時(shí)器
mtimer.start(1000);

4.停止定時(shí)器
mtimer.stop();

QT Creator組件布局

運(yùn)行效果

源碼

stopwatchwin.h

#ifndef STOPWATCHWIN_H
#define STOPWATCHWIN_H
?
#include <QMainWindow>
#include <QTime>
#include <QTimer>
namespace Ui {
class StopwatchWin;
}
?
class StopwatchWin : public QMainWindow
{
? ? Q_OBJECT
?
public:
? ? explicit StopwatchWin(QWidget *parent = nullptr);
? ? ~StopwatchWin();
? ? void fun_clicked();
?
private slots:
? ? void on_pushButton_clicked();
?
? ? void on_startBt_clicked();
?
? ? void on_stopBtn_clicked();
?
? ? void on_recordBtn_clicked();
?
? ? void on_resertBt_clicked();
?
private:
? ? Ui::StopwatchWin *ui;
? ? //QTime t;
? ? QTime t = QTime(0,0,0,0);
? ? QTimer mtimer;
};
?
#endif // STOPWATCHWIN_H

stopwatchwin.cpp

#include "stopwatchwin.h"
#include "ui_stopwatchwin.h"
#include <QDebug>
StopwatchWin::StopwatchWin(QWidget *parent) :
? ? QMainWindow(parent),
? ? ui(new Ui::StopwatchWin)
{
? ? ui->setupUi(this);
? ? //把定時(shí)器信號(hào)與槽函數(shù)關(guān)聯(lián)
? ? connect(&mtimer, &QTimer::timeout, this, &StopwatchWin::fun_clicked);
}
?
StopwatchWin::~StopwatchWin()
{
? ? delete ui;
}
?
void StopwatchWin::fun_clicked()
{
? ? QString tim = t.toString("hh:mm:ss:zzz");
? ? t = t.addMSecs(10);
? ? ui->lcdNumber->display(tim);
? ? qDebug()<<"1111";
}
void StopwatchWin::on_startBt_clicked()
{
? ? qDebug()<<"啟動(dòng)定時(shí)器";
? ? mtimer.start(10);
}
?
void StopwatchWin::on_stopBtn_clicked()
{
? ? qDebug()<<"停止定時(shí)器";
? ? if(mtimer.isActive())
? ? {
? ? ? ? mtimer.stop();
? ? }
}
?
void StopwatchWin::on_pushButton_clicked()
{
?
}
?
void StopwatchWin::on_recordBtn_clicked()
{
? ? QString tim = t.toString("hh:mm:ss:zzz");
? ? ui->textBrowser->append(tim);
}
?
void StopwatchWin::on_resertBt_clicked()
{
? ?t = QTime(0,0,0,0);
}

main.cpp

#include "stopwatchwin.h"
#include <QApplication>
?
int main(int argc, char *argv[])
{
? ? QApplication a(argc, argv);
? ? StopwatchWin w;
? ? w.show();
?
? ? return a.exec();
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論