当前位置:网站首页>[QT] timer
[QT] timer
2022-07-04 05:04:00 【StudyWinter】
1 The first way
(1) Using events void timerEvent ( QTimerEvent * ev)
(2) Start timer startTimer( 1000) Millisecond unit
(3)timerEvent The return value of is the unique identifier of the timer You can talk to ev->timerid compare
demand : Set two timers , Time is different .
(1) The first is rewriting timerEvent function
Add... Here UI Of label Control
rewrite
// Timer event
void Widget::timerEvent(QTimerEvent *event) {
if (event->timerId() == this->m_Id1) {
static int num = 1;
ui->label->setText(QString::number(num++));
} else if (event->timerId() == this->m_Id2){
static int num2 = 1;
ui->label_2->setText(QString::number(num2++));
}
}
(2) Because there are two timers , Add member attributes to the class , Each represents the return value of two timers
(3) Start two timers
// Start timer
this->m_Id1 = startTimer(1000); // millisecond
this->m_Id2 = startTimer(2000);
(4) effect
2 The second way
Timer class
// Timer class
QTimer* timer = new QTimer(this);
timer->start(500); // In milliseconds
// Monitor the signal of timer object
connect(timer, &QTimer::timeout, this, [=](){
static int num3 = 1;
ui->label_3->setText(QString::number(num3++));
});
effect
expand , Click the pause button , The timer pauses
add to QPushbutton Button , Use connect Make connections
// Click pause , Implementation stop
connect(ui->btn_pause, &QPushButton::clicked, this, [=](){
timer->stop();
});
effect
边栏推荐
- STM32F1与STM32CubeIDE编程实例-74HC595驱动4位7段数码管
- Create ASM disk through DD
- 【MATLAB】MATLAB 仿真 — 模拟调制系统 之 AM 调制过程
- 【MATLAB】通信信号调制通用函数 — 窄带高斯白噪声的生成
- Roles of rollup components
- 6-4 vulnerability exploitation SSH banner information acquisition
- Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
- Annex III: scoring standard of the defender docx
- laravel 中获取刚刚插入的记录的id
- Share some of my telecommuting experience
猜你喜欢
NTFS 安全权限
简单g++和gdb调试
电子元器件商城与数据手册下载网站汇总
中職組網絡安全—內存取證
Zhongke panyun-d module analysis and scoring standard
Headache delayed double deletion
Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire
定制一个自己项目里需要的分页器
中科磐云—2022广东木马信息获取解析
Detailed comparison of Hynix emmc5.0 and 5.1 series
随机推荐
附件四:攻击方评分标准.docx
YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
Useful plug-ins for vscode
【MATLAB】通信信号调制通用函数 — 傅里叶变换
Several smart watch related chips Bluetooth chip low power consumption
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
Yolov6 practice: teach you to use yolov6 for object detection (with data set)
laravel 中获取刚刚插入的记录的id
Utiliser des unités de mesure dans votre code pour une vie meilleure
如何构建属于自己的知识引擎?社群开放申请
[untitled]
appliedzkp zkevm(11)中的EVM Proof
记几个智能手表相关芯片 蓝牙芯片 低功耗
Share some of my telecommuting experience
Customize a pager needed in your project
[matlab] general function of communication signal modulation Fourier transform
2022 Guangdong provincial competition - code information acquisition and analysis flag
【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
[matlab] matlab simulation modulation system - DSB system
中科磐云—D模块解析以及评分标准