当前位置:网站首页>QPushButton slot function is triggered multiple times
QPushButton slot function is triggered multiple times
2022-04-23 04:57:00 【Tcoder-l3est】
QPushbutton The slot function is triggered multiple times
Before the change
--------------TODO Binding function --------------
For screen / End the screen shot
connect(&this->attachToDevice, &QPushButton::clicked, this, &PhoneCard::onAttachToDevice);
connect(&this->detachFromDevice, &QPushButton::clicked, this, &PhoneCard::onDetachFromDevice);
The signal slot will be bound every time , But not rebinding , That is, it becomes multiple signal slots
therefore Every time you click the refresh button Click again The refreshed key , The refreshed button will have an additional trigger mechanism ( For the time being )
Then when you click again After the refreshed button It will trigger multiple times . In the corresponding QMessageBox There will be many times
solve
void PhoneCard::drawButtons(int modType) {
// to phone
if(modType == 1){
// Put it on the phone
this->attachToDevice.setParent(this);
this->attachToDevice.setGeometry(40,110,220,30);
this->attachToDevice.setText(" Drop to this device ");
this->attachToDevice.setFont(QFont("Times New Roman"));
this->attachToDevice.setStyleSheet(style_but);
this->attachToDevice.show();
// disconnect
this->detachFromDevice.setParent(this);
this->detachFromDevice.setGeometry(40,150,220,30);
this->detachFromDevice.setText(" Stop screen projection ");
this->detachFromDevice.setFont(QFont("Times New Roman"));
this->detachFromDevice.setStyleSheet(style_but);
this->detachFromDevice.show();
--------------TODO Binding function --------------
For screen / End the screen shot Because many times So first Unbundling then Again binding
this->attachToDevice.disconnect();
this->detachFromDevice.disconnect();
connect(&this->attachToDevice, &QPushButton::clicked, this, &PhoneCard::onAttachToDevice);
connect(&this->detachFromDevice, &QPushButton::clicked, this, &PhoneCard::onDetachFromDevice);
this->usb.hide();
this->wifi.hide();
}
else if(modType == 0){
// to phone
// wifi Key
this->wifi.setParent(this);
this->wifi.setGeometry(40,110,220,30);
this->wifi.setText("Wifi Connect ");
this->wifi.setFont(QFont("Times New Roman"));
this->wifi.setStyleSheet(style_but);
this->wifi.show();
// USB
this->usb.setParent(this);
this->usb.setGeometry(40,150,220,30);
this->usb.setText("USB Connect ");
this->usb.setFont(QFont("Times New Roman"));
this->usb.setStyleSheet(style_but);
this->usb.show();
--------------TODO Binding function --------------
Untie yourself WiFi USB
Rebind
}
else if(modType == -1){
this->attachToDevice.hide();
this->detachFromDevice.hide();
this->usb.hide();
this->wifi.hide();
}
}
That is, before each binding disconnect Again connect
Of course This estimate only applies to Corresponding to a slot function , If it corresponds to multiple , You may have to rebind more than one at a time ~
other BUG
Repair After starting the screen projection Click refresh “ On screen ” The button is reset, but In a constant state bug
fungcard.h Add these built-in functions
QString getAttachStatus(){
return this->attachToDevice.text();
}
QString getWifiStatus(){
return this->wifi.text();
}
QString getUsbStatus(){
return this->usb.text();
}
And then in mainmenu.cpp When clicking refresh Re judge Make a stop
void MainMenu::onRefreshClicked() {
// Determine the current status according to the text
int findType = -1;
if(ToPhoneButton.text() == " Has run ")
findType = 1;
else if(ToPCButton.text() == " Has run ")
findType = 0;
else{
QMessageBox::information(this,"JoyStick", " Please select the mode on the left first !",QMessageBox::Ok);
return ;
}
for (PhoneCard &phone : phoneCards) {
if(phone.getAttachStatus() == " On screen ..." || phone.getWifiStatus() == " On screen ..." || phone.getUsbStatus() == " On screen ...")
{
QMessageBox::information(this,"JoyStick", " Some screens have not stopped , Please stop and refresh !",QMessageBox::Ok);
return;
}
}
int number = 0;
for (PhoneCard &phone : phoneCards) {
phone.setParent(this);
phone.drawOnRefresh(number++,findType);
}
}
The lesson here is inline To get the state and judge
版权声明
本文为[Tcoder-l3est]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230452447103.html
边栏推荐
- Progress of innovation training (IV)
- Learning Android from scratch -- Introduction
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Wine (COM) - basic concept
- Unity3d practical skills - theoretical knowledge base (I)
- js 判断数字字符串中是否含有字符
- leetcode——启发式搜索
- Gets all dates between two times
- Learning Android from scratch -- baseactivity and activitycollector
- TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
猜你喜欢
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
Detailed explanation of the differences between TCP and UDP
AQS source code reading
PHP+MySQL 制作留言板
[database] MySQL multi table query (I)
Spark small case - RDD, spark SQL
DIY 一个 Excel 版的子网计算器
泰克示波器DPO3054自校准SPC失败维修
Details related to fingerprint payment
Excel protects worksheets and workbooks from damage
随机推荐
JS engine loop mechanism: synchronous, asynchronous, event loop
Spark small case - RDD, spark SQL
深度学习笔记 —— 物体检测和数据集 + 锚框
How to exit VIM
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Innovation training (VII) FBV view & CBV view
Informatics Olympiad 1955: [11noip popularization group] Swiss round | openjudge 4.1 4363: Swiss round | Luogu p1309 [noip2011 popularization group] Swiss round
2022/4/22
Com alibaba. Common methods of fastjson
Unity C# 网络学习(四)
JS determines whether the numeric string contains characters
Learning Android II from scratch - activity
深度学习笔记 —— 微调
Spark small case - RDD, broadcast
Thoughts on a small program
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
AQS源码阅读
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
Unity rawimage background seamlessly connected mobile