当前位置:网站首页>About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)
About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)
2022-06-30 14:06:00 【Fat Xiao Deng】
Why? QPushButton( for the first time ) It takes two clicks to respond ?
I found a problem when learning the timer class ( I wonder if ?).
ask : When clicking pause 1 when , Mouse to double-click , The timer will stop , see Qt Assistant pair clicked Obviously not 
translate : When the button is activated ( namely , Press and release when the mouse cursor is inside the button ), When you type a shortcut key , Or when click() or animateClick() When called , This signal is sent . It is worth noting that , If the setDown()、setChecked() or toggle(), This signal will not be sent .
understand : Shouldn't it be a mouse click ?

#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
// Create a timer object
timer1 = new QTimer(this);
timer2 = new QTimer(this);
// Object on
timer1->start(500);
timer2->start(1000);
int num1=0;
int num2=0;
// When the timer is turned on, a timeout The signal
connect(timer1,&QTimer::timeout,[=]()mutable{
ui->label->setText(QString::number(num1++));
});
connect(timer2,&QTimer::timeout,[=]()mutable{
ui->label_2->setText(QString::number(num2++));
});
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()// Pause 1
{
connect(ui->pushButton, &QPushButton::clicked,this,[=](){
timer1->stop();// Click twice to stop ???
});
}
void Widget::on_pushButton_2_clicked()// continue 1
{
connect(ui->pushButton_2, &QPushButton::clicked,this,[=](){
timer1->start(500);
});
}
** attach :** This is my in windows Up operation Qt(5.7.0) When I met
** reflection :** This sum doubleClicked What's the difference ?
This signal is emitted when the button is interactively double clicked by the user.
When the user interactively double clicks the button , Will send this signal .
Now record .
** solve :** The above problem is caused by turning to the slot , If you write the code of clicking the button into the constructor, there will be no problem .
边栏推荐
- DNS 解析之家庭网络接入 Public DNS 实战
- 可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈
- Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation
- Deep understanding Net (2) kernel mode 4 Summary of kernel pattern constructs
- “即服务”,企业数字化转型的必然选择
- Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set
- 重磅:国产IDE发布,由阿里研发,完全开源!
- 深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结
- How does MySQL merge columns?
- Shell programming overview
猜你喜欢

【 scientific literature measurement 】 mining and visualization of keywords in foreign and Chinese Literature

Observable, seulement fiable: première bombe de salon de la série cloudops d'exploitation et d'entretien automatisés dans le nuage

"Persistent diseases" that cannot be solved in IM application development

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

Kaniko official documents - build images in kubernetes

智慧运维:基于 BIM 技术的可视化管理系统

Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!

What is erdma as illustrated by Coptic cartoon?

This editor will open source soon!

【刷题篇】供暖器
随机推荐
幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
"Persistent diseases" that cannot be solved in IM application development
get请求与post提交区别的简易理解
【Kubernetes系列】K8s设置MySQL8大小写不敏感
DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
exlipse同时操作多行。比如同时在多行同列输入相同的文字
A keepalived high availability accident made me learn it again!
[kali] Kali system, software update (with image source)
SQL考勤统计月报表
WTM major updates, multi tenancy and single sign on
[kubernetes series] k8s set mysql8 case insensitive
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
Introduction to two types of rxjs observable operators
Jetpack compose for perfect screen fit
Exlipse operates on multiple rows at the same time. For example, input the same text in multiple lines and columns at the same time
Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set
This article explains the concepts of typed array, arraybuffer, typedarray, DataView, etc
Rpm2rpm packaging steps
第四批入围企业公示——年度TOP100智能网联供应商评选