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类的使用方法。

相关推荐
BatyTao37 分钟前
QT Creator快速创建主项目-子项目
qt
赤水无泪3 小时前
Qt 全模块汇总列表
开发语言·qt
GoKu~4 小时前
QT视图界面
qt
冰山一脚20136 小时前
QWidget的初始化颜色来自于哪里的笔记
qt
小陶来咯8 小时前
aimrt中间件的使用
开发语言·qt·中间件
music score9 小时前
google 的C++自动化测试框架详解(Google Test)(2)
c++·qt·lucene
小短腿的代码世界9 小时前
Qt_Qwt深度解析:从源码到工业级性能优化
开发语言·qt·性能优化
GoKu~9 小时前
QT Qss
qt
基德爆肝c语言9 小时前
Qt系统相关
开发语言·qt
星河漫步Lu10 小时前
QT6中五步完成Android的环境配置
android·qt