当前位置:网站首页>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
边栏推荐
- Case of using stream load to write data to Doris
- Innovation training (10)
- What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
- redis和mysql区别
- Other problems encountered in debugging fingerprints
- Detailed explanation of hregionserver
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Mac 进入mysql终端命令
- Innovation training (VI) routing
- What's the difference between error and exception
猜你喜欢

深度学习笔记 —— 微调

Making message board with PHP + MySQL

深度学习笔记 —— 物体检测和数据集 + 锚框

AQS source code reading

Sword finger offer: the path with a certain value in the binary tree (backtracking)

DIY 一个 Excel 版的子网计算器

Excel protects worksheets and workbooks from damage
![[database] MySQL basic operation (basic operation ~)](/img/0c/a8d858fa74ffed2a266ca77c783c7f.png)
[database] MySQL basic operation (basic operation ~)

Wine (COM) - basic concept

Innovation training (V) configuration information
随机推荐
Innovation training (V) mid term inspection
Mac 进入mysql终端命令
General enumeration constant class
C# List字段排序含有数字和字符
泰克示波器DPO3054自校准SPC失败维修
Use AES encryption - reuse the wisdom of predecessors
Case of using stream load to write data to Doris
简单的拖拽物体到物品栏
Innovation training (XII) reptile
Simply drag objects to the item bar
C list field sorting contains numbers and characters
unity摄像机旋转带有滑动效果(自转)
Installation and deployment of Flink and wordcount test
Excel protects worksheets and workbooks from damage
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
Informatics Olympiad 1955: [11noip popularization group] Swiss round | openjudge 4.1 4363: Swiss round | Luogu p1309 [noip2011 popularization group] Swiss round
AQS source code reading
Differences between redis and MySQL
Teach you how to build the ruoyi system by Tencent cloud