首页 > 其他 > 详细

qt5--定时器

时间:2019-09-19 17:23:22      阅读:94      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

定时器方式一:----定时器事件

需要     #include <QTimerEvent>

 

#include "win.h"
#include <QDebug>
#include <QPushButton>


Win::Win(QWidget *parent)
    : QWidget(parent)
{
    this->resize(500,400);
    this->setWindowTitle("定时器");
    this->move(700,100);

    QPushButton* btn=new QPushButton("按钮",this);
    btn->move(400,350);
    connect(btn,&QPushButton::clicked,this,&Win::A);

    label=new QLabel("标签标签",this);
    label->move(10,10);
    label->resize(200,50);
    label->setFrameShape(QFrame::Box);

    label1=new QLabel("标签1",this);
    label1->move(10,70);

    ID=startTimer(1000);//启动定时器事件,创建一个定时器并返回定时器ID
    //参数:单位毫秒---每隔n毫秒时间,就执行一次定时器事件
    //返回值:定时器ID号
    ID1=startTimer(2000);


}
void Win::timerEvent(QTimerEvent *e){
    static int i,j=0;
    if(e->timerId()==ID){    //如果定时号是ID
        label->setText(QString::number(i++));
    }
    if(e->timerId()==ID1){
        label1->setText(QString::number(j++));
    }



}

Win::~Win()
{

}


void Win::A(){

}

 

 

 

 

技术分享图片

qt5--定时器

原文:https://www.cnblogs.com/liming19680104/p/11550712.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!