最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Qt實(shí)現(xiàn)定時(shí)器的兩種方法分享

 更新時(shí)間:2022年11月28日 09:27:20   作者:天人合一peng  
這篇文章主要為大家詳細(xì)介紹了Qt中實(shí)現(xiàn)定時(shí)器的兩種不同方法,文中的示例代碼講解詳細(xì),對(duì)我們了解Qt有一定的幫助,感興趣的可以跟隨小編一起學(xué)習(xí)一下

方法一

視頻教程

生成widget基類對(duì)象

添加兩個(gè)txtlabel

#ifndef WIDGET_H
#define WIDGET_H
 
#include <QWidget>
 
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
 
class Widget : public QWidget
{
    Q_OBJECT
 
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
 
   void timerEvent(QTimerEvent* timer);
   int timeId1;
   int timeId2;
 
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
//#include <QTimerEvent>
//#include <QTimer>
 
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
 
 
    timeId1 = startTimer(1000);
 
    timeId2 =startTimer(2000);
 
}
 
 void Widget::timerEvent(QTimerEvent* timer)
 {
  if(timer->timerId() == timeId1)
  {
 
     static int num = 1;
     ui->label_3->setText(QString::number(num++));
  }
  else if(timer->timerId() == timeId2)
  {
      static int num = 1;
      ui->label_4->setText(QString::number(num++));
  }
 
 }
 
Widget::~Widget()
{
    delete ui;
}

效果圖 

方法二

視頻教程

#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QTimer>
 
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
 
 
    timeId1 = startTimer(1000);
 
    timeId2 =startTimer(2000);
 
    QTimer* timer = new QTimer(this);
 
    timer->start(500);
    connect(timer, &QTimer::timeout,[=]()
    {
 
        static int num = 1;
        ui->label_5->setText(QString::number(num++));
 
    });
//    定時(shí)器停止
//    connect(ui->pushbtn_stop, &QPushButton::clicked, timer,&QTimer::stop);
 
    connect(ui->pushbtn_stop, &QPushButton::clicked, [=](){
        timer->stop();
    });
 
 
 
 
 
}
 
 void Widget::timerEvent(QTimerEvent* timer)
 {
  if(timer->timerId() == timeId1)
  {
 
     static int num = 1;
     ui->label_3->setText(QString::number(num++));
  }
  else if(timer->timerId() == timeId2)
  {
      static int num = 1;
      ui->label_4->setText(QString::number(num++));
  }
 
 }
 
Widget::~Widget()
{
    delete ui;
}

效果圖

到此這篇關(guān)于Qt實(shí)現(xiàn)定時(shí)器的兩種方法分享的文章就介紹到這了,更多相關(guān)Qt定時(shí)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

东兴市| 阿荣旗| 嘉善县| 佛冈县| 新竹县| 陇川县| 固原市| 盱眙县| 东丽区| 扎囊县| 安阳市| 获嘉县| 吉水县| 南宫市| 香河县| 拉萨市| 十堰市| 樟树市| 军事| SHOW| 板桥市| 罗山县| 叶城县| 永新县| 太原市| 称多县| 怀远县| 旬阳县| 灯塔市| 湘阴县| 临夏市| 奈曼旗| 炎陵县| 石泉县| 高阳县| 玉山县| 文化| 德庆县| 白水县| 东乌珠穆沁旗| 称多县|