当前位置:网站首页>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 .
边栏推荐
- Je suis à Foshan, où puis - je ouvrir un compte? L'ouverture d'un compte par téléphone mobile est - elle sécurisée?
- 【刷题篇】避免洪水泛滥
- 幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
- 华为帐号多端协同,打造美好互联生活
- 【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
- Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone
- IM即时通讯应用开发中无法解决的“顽疾”
- 提权扫描工具
- Golang template (text/template)
- 【系统分析师之路】第五章 复盘软件工程(软件过程改进)
猜你喜欢
![【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

Step by step | help you easily submit Google play data security form

Today's sleep quality record 80 points
![[Title brushing] coco, who likes bananas](/img/66/5646ac7e644025ccaee7c17f62ce17.png)
[Title brushing] coco, who likes bananas

Apache Doris Compaction優化百科全書

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

Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance

SQL attendance statistics monthly report

深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结

单元测试效率优化:为什么要对程序进行测试?测试有什么好处?
随机推荐
Wuenda 2022 machine learning special course evaluation is coming!
Loss function: Diou loss handwriting implementation
Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)
点击table的td单元格出现dialog弹窗,获取值后将值放回td单元格
numpy 创建空数组 data = np.empty(shape=[1, 64,64,3])
[Title brushing] coco, who likes bananas
【刷题篇】爱吃香蕉的珂珂
How to take the first step in digital transformation
Begin End use the pit encountered
Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
Directory related commands
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
Publicity of the fourth batch of shortlisted Enterprises - annual Top100 smart Internet supplier selection
This editor will open source soon!
重磅:国产IDE发布,由阿里研发,完全开源!
【科学文献计量】外文文献及中文文献关键词的挖掘与可视化
损失函数:DIOU loss手写实现
Exlipse operates on multiple rows at the same time. For example, input the same text in multiple lines and columns at the same time
JMeter transaction controller
数据库表为什么写不进数据了