当前位置:网站首页>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 .
边栏推荐
- [deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"
- Simple understanding of the difference between get request and post submission
- Embedded development: five C features that may no longer be prohibited
- Why can't the database table be written into data
- How to execute a query SQL
- Yousi College: Six Sigma is not just statistics!
- Jetpack Compose 实现完美屏幕适配
- 【刷题篇】供暖器
- SQL attendance statistics monthly report
- [Title brushing] coco, who likes bananas
猜你喜欢

Kaniko official documents - build images in kubernetes

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

步骤详解 | 助您轻松提交 Google Play 数据安全表单
![【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/70/8bf226964118efb324ca4d339df654.png)
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
![[KALI] KALI系统、软件更新(附带镜像源)](/img/ac/43a3f81d50ab6866271b500b142252.png)
[KALI] KALI系统、软件更新(附带镜像源)

Lifting scanning tool

Unity animator parameter

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

SQL考勤统计月报表
随机推荐
Dart 扩展特性
How does MySQL merge columns?
Rpm2rpm packaging steps
"Persistent diseases" that cannot be solved in IM application development
【系统分析师之路】第五章 复盘软件工程(软件过程改进)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
这个编辑器即将开源!
How can I protect my private key?
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
Numpy creates an empty array data = np empty(shape=[1, 64,64,3])
DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
Publicity of the fourth batch of shortlisted Enterprises - annual Top100 smart Internet supplier selection
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
[Title brushing] heater
逆向调试入门-PE中的VA与RVA换算04/07
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
【刷题篇】供暖器
Step by step | help you easily submit Google play data security form
navicat数据库建表是没有utf8选项。
SQL programming problem, test case failed