当前位置:网站首页>QPushbutton 槽函数被多次触发
QPushbutton 槽函数被多次触发
2022-04-23 04:52:00 【Tcoder-l3est】
QPushbutton 槽函数被多次触发
修改前
--------------TODO绑定函数--------------
投屏/结束投屏
connect(&this->attachToDevice, &QPushButton::clicked, this, &PhoneCard::onAttachToDevice);
connect(&this->detachFromDevice, &QPushButton::clicked, this, &PhoneCard::onDetachFromDevice);
每次都会绑定信号槽,但是不是重新绑定的,也就是变成多个信号槽了
所以 每次点击刷新按键之后 再点击 被刷新的按键 ,被刷新的按键都会多一个触发机制(暂且这么理解)
然后当你再次点击 被刷新的按钮之后 就会导致触发多次。对应的里面加的QMessageBox 就会出现多次
解决
void PhoneCard::drawButtons(int modType) {
// to phone
if(modType == 1){
// 投到手机
this->attachToDevice.setParent(this);
this->attachToDevice.setGeometry(40,110,220,30);
this->attachToDevice.setText("投屏到此设备");
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("停止投屏");
this->detachFromDevice.setFont(QFont("Times New Roman"));
this->detachFromDevice.setStyleSheet(style_but);
this->detachFromDevice.show();
--------------TODO绑定函数--------------
投屏/结束投屏 因为多次绘制 所以需要首先 解绑 然后 再 绑定
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按键
this->wifi.setParent(this);
this->wifi.setGeometry(40,110,220,30);
this->wifi.setText("Wifi 连接");
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 连接");
this->usb.setFont(QFont("Times New Roman"));
this->usb.setStyleSheet(style_but);
this->usb.show();
--------------TODO绑定函数--------------
解绑自己WiFi USB
重新绑定
}
else if(modType == -1){
this->attachToDevice.hide();
this->detachFromDevice.hide();
this->usb.hide();
this->wifi.hide();
}
}
即每次绑定前先disconnect 再重新 connect
当然 这个估计只适用于 对应一个槽函数,如果对应多个,可能就得每次重新绑定多个了~
其他BUG
修复 开始投屏后 点击刷新 “投屏中” 按钮被重置但是 状态不变的bug
fungcard.h 里面加这几个内置函数
QString getAttachStatus(){
return this->attachToDevice.text();
}
QString getWifiStatus(){
return this->wifi.text();
}
QString getUsbStatus(){
return this->usb.text();
}
然后在mainmenu.cpp 点刷新时 重新判断一下 进行一个阻止
void MainMenu::onRefreshClicked() {
// 根据文本决定当前状态
int findType = -1;
if(ToPhoneButton.text() == "已运行")
findType = 1;
else if(ToPCButton.text() == "已运行")
findType = 0;
else{
QMessageBox::information(this,"JoyStick", "请先在左侧选择模式!",QMessageBox::Ok);
return ;
}
for (PhoneCard &phone : phoneCards) {
if(phone.getAttachStatus() == "投屏中..." || phone.getWifiStatus() == "投屏中..." || phone.getUsbStatus() == "投屏中...")
{
QMessageBox::information(this,"JoyStick", "有投屏还未停止,请停止后刷新!",QMessageBox::Ok);
return;
}
}
int number = 0;
for (PhoneCard &phone : phoneCards) {
phone.setParent(this);
phone.drawOnRefresh(number++,findType);
}
}
这里的启示就是 inline 来获取状态加以判断
版权声明
本文为[Tcoder-l3est]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_47865838/article/details/124297199
边栏推荐
- Innovation training (10)
- 信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
- Last day of 2017
- Painless upgrade of pixel series
- C# List字段排序含有数字和字符
- Spark small case - RDD, broadcast
- 跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
- Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
- Spark FAQ sorting - must see before interview
- Agile practice | agile indicators to improve group predictability
猜你喜欢
Innovation training (IX) integration
What is a data island? Why is there still a data island in 2022?
New terminal play method: script guidance independent of technology stack
Thoughts on a small program
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
简单的拖拽物体到物品栏
Wechat payment function
Perfect test of coil in wireless charging system with LCR meter
用LCR表完美测试无线充电系统中的线圈
随机推荐
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
Innovation training (VI) routing
PIP3 installation requests Library - the most complete pit sorting
2022/4/22
Eight misunderstandings that should be avoided in data visualization
Implementation of switching windows and capturing data in selenium mode
leetcode007--判断字符串中的括号是否匹配
Windows remote connection to redis
MySQL time function query
redis和mysql区别
Wechat payment function
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
Spark case - wordcount
[WinUI3]编写一个仿Explorer文件管理器
Special topic of data intensive application system design
Informatics Aosai yibentong 1212: letters | openjudge 2.5 156: Letters
leetcode008--实现strStr()函数
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
Learning Android from scratch -- Introduction
Innovation training (IX) integration