QTimer类的使用方法

本文介绍QTimer类的使用方法。

1.单次触发

在某些情况下,定时器只运行一次,可使用单次触发方式。

cpp 复制代码
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MainWindow::timeout);
timer->setSingleShot(true);
timer->start(1000);

void MainWindow::timeout()
{



}

或直接采用静态方法:

cpp 复制代码
QTimer::singleShot(1000, this, &MainWindow::timeout);

void MainWindow::timeout()
{



}

2.重复触发

定时器需要重复触发,可采用重复触发方式。

cpp 复制代码
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MainWindow::timeout);
timer->start(1000);

timer->stop();  //stop timer

void MainWindow::timeout()
{



}

总结,本文介绍了Qt编程中QTimer类的使用方法。

相关推荐
TechNomad1 小时前
Qt开发:QtConcurrent介绍和使用
qt
十秒耿直拆包选手11 小时前
Qt:主窗体(QMainwindow)初始化注意事项
c++·qt
-凌凌漆-18 小时前
【Qt】Qt QML json处理
开发语言·qt·json
海天鹰21 小时前
Qt:图片切割
qt
做一个坚强的女汉子1 天前
QT保存日志到文件中以及捕捉崩溃日志
开发语言·qt
顾苏洋19901 天前
qt绘制饼状图并实现点击即放大点击部分
开发语言·qt
笑鸿的学习笔记1 天前
qt-C++笔记之布局管理`space` 和 `margin`的区别
c++·笔记·qt
轩情吖1 天前
Qt常用控件之QWidget(一)
c++·qt·geometry·qwidget·qpushbutton·客户端开发·enabled
没学上了1 天前
Qt去噪面板搭建
开发语言·qt
peihexian1 天前
vcpkg交叉编译qt等过程记录(未完成)
开发语言·qt