Qt 类之:QTimer

QTimer常用的几种写法:

1、SingleShot:只发送一次timeout信号

QTimer *timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start();

 

2、默认时间间隔为0,不停的发送信号timeout

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start();

 

3、setInterval:相隔指定时间后,发一次信号timeout

QTimer *timer = new QTimer(this);
timer->setInterval(3000);
connect(timer,SIGNAL(timeout()),this,SLOT(print()));
timer->start();

 

4、start(std::chrono::milliseconds msec):相隔指定时间后,发一次信号timeout,执行效果同3

QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(print()));
timer->start(3000);

 

posted @ 2020-04-26 20:35  世纪强风  阅读(1143)  评论(0编辑  收藏  举报