当前位置:网站首页>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
边栏推荐
- The unity camera rotates with the mouse
- Better way to read configuration files than properties
- Day. JS common methods
- Learning Android V from scratch - UI
- AQS源码阅读
- Progress of innovation training (III)
- What is the meaning of load balancing
- View, modify and delete [database] table
- Innovation training (V) mid term inspection
- Installation and deployment of Flink and wordcount test
猜你喜欢
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
DIY 一个 Excel 版的子网计算器
【数据库】MySQL基本操作(基操~)
Field injection is not recommended using @ Autowired
Introduction to raspberry pie 3B - system installation
POI export message list (including pictures)
Details related to fingerprint payment
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
Use the built-in function of win to transfer files between two computers in the same LAN (the speed is the same as that between local disks)
深度学习笔记 —— 语义分割和数据集
随机推荐
Field injection is not recommended using @ Autowired
js 判断数字字符串中是否含有字符
退出vim的方法
The programmer starts the required application with one click of window bat
Opencv + clion face recognition + face model training
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
Innovation training (V) configuration information
PHP counts the number of files in the specified folder
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
Introduction to raspberry pie 3B - system installation
DIY 一个 Excel 版的子网计算器
洛谷P2731骑马修栅栏
AQS source code reading
Pixel mobile phone brick rescue tutorial
Informatics Aosai yibentong 1212: letters | openjudge 2.5 156: Letters
leetcode——启发式搜索
C list field sorting contains numbers and characters
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
Mac 进入mysql终端命令