" />

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

Qt編寫(xiě)秒表功能

 更新時(shí)間:2022年08月04日 12:13:09   作者:勤勉之  
這篇文章主要為大家詳細(xì)介紹了Qt編寫(xiě)秒表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Qt編寫(xiě)秒表的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

文件widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include<QTimer>
#include <QWidget>
#include<QString>
#include<QTime>
namespace Ui {
class Widget;
}
?
class Widget : public QWidget
{
? ? Q_OBJECT
?
public:
? ? explicit Widget(QWidget *parent = 0);
? ? ~Widget();
?
private slots:
? ? void on_startButton_clicked();
? ? void updatesolt();
? ? void on_stopButton_clicked();

private:
? ? Ui::Widget *ui;
? ? int num ;
? ? QTimer *timer;
?
};
?
#endif // WIDGET_H

main.cpp

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

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include<QString>
#include<QTime>
Widget::Widget(QWidget *parent) :
? ? QWidget(parent),
? ? ui(new Ui::Widget)
{
? ? ui->setupUi(this);
? ? num = ?0;
? ?// ui->lineEdit->setText(QString::number(num));
? ? ui->lcdNumber->setDigitCount(8);
? ? QTime time;
? ? time.setHMS(0,0,0);
? ? ui->lcdNumber->display(time.toString("hh:mm:ss"));
? ? //這個(gè)this是為了指定父對(duì)象,
? ? //只要指定了父對(duì)象,那么在堆區(qū)申請(qǐng)的空間,會(huì)在釋放父對(duì)象的時(shí)候,會(huì)自動(dòng)釋放
? ? timer = new QTimer(this);
? ? //只要設(shè)定的時(shí)間到,timer 就會(huì)產(chǎn)生一個(gè)timeout的信號(hào),而且是循環(huán)產(chǎn)生
? ? connect(timer,SIGNAL(timeout()),this,SLOT(updatesolt()));
}
?
Widget::~Widget()
{
? ? delete ui;
}
?
void Widget::on_startButton_clicked()
{
? ? //啟動(dòng)定時(shí)器 ?單位是毫秒
? ? timer->start(10);
?
}
void Widget::updatesolt()
{
? ? num++;
? ? QTime time(0,0,0);
? ? QTime t = time.addSecs(num);
? ? ui->lcdNumber->display(t.toString("hh:mm:ss"));
}
?
?
void Widget::on_stopButton_clicked()
{
? ? timer->stop();
}

UI界面如下:

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

相關(guān)文章

最新評(píng)論