当前位置:网站首页>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 .
边栏推荐
- How does MySQL merge columns?
- 服务线上治理
- [kubernetes series] k8s set mysql8 case insensitive
- Click the TD cell of table to open the dialog pop-up window. After obtaining the value, put the value back into the TD cell
- 用Unity实现Flat Shading
- 数据库表为什么写不进数据了
- Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
- 可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈
- This article explains the concepts of typed array, arraybuffer, typedarray, DataView, etc
- 损失函数:DIOU loss手写实现
猜你喜欢
Defi "where does the money come from"? A problem that most people don't understand
【刷题篇】避免洪水泛滥
Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone
[kali] Kali system, software update (with image source)
Loss function: Diou loss handwriting implementation
navicat数据库建表是没有utf8选项。
【观察】智能产业加速,为何AI算力要先行?
A keepalived high availability accident made me learn it again!
Getting started with shell Basics
可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
随机推荐
Prometheus 2.29.0 new features
navicat数据库建表是没有utf8选项。
mysql拒绝访问、管理员身份打开的
Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation
Inexplicable error occurred in unity's frequent switching branch result model
香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
How to execute a query SQL
【Kubernetes系列】K8s设置MySQL8大小写不敏感
Yousi College: Six Sigma is not just statistics!
深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结
Loss function: Diou loss handwriting implementation
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
(8)JMeter元件详解之 Once only Controller 仅一次控制器
Dart 扩展特性
【系统分析师之路】第五章 复盘软件工程(敏捷开发)
How can c write an SQL parser
Observable, seulement fiable: première bombe de salon de la série cloudops d'exploitation et d'entretien automatisés dans le nuage
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
步骤详解 | 助您轻松提交 Google Play 数据安全表单