当前位置:网站首页>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
边栏推荐
- Leetcode -- heuristic search
- The programmer starts the required application with one click of window bat
- Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
- Introduction to raspberry pie 3B - system installation
- Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
- Field injection is not recommended using @ Autowired
- Custom switch control
- AQS源码阅读
- MySQL - index
- Record the ThreadPoolExecutor main thread waiting for sub threads
猜你喜欢

Details related to fingerprint payment

Windows remote connection to redis

CLion+OpenCV identify ID number - detect ID number

JS engine loop mechanism: synchronous, asynchronous, event loop

MySQL -- execution process and principle of a statement

Record the ThreadPoolExecutor main thread waiting for sub threads

Making message board with PHP + MySQL

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

【数据库】MySQL基本操作(基操~)

Leetcode 1547: minimum cost of cutting sticks
随机推荐
POI export message list (including pictures)
Sword finger offer: push in and pop-up sequence of stack
洛谷P2731骑马修栅栏
Learning Android II from scratch - activity
Wechat payment function
Record the ThreadPoolExecutor main thread waiting for sub threads
PHP 统计指定文件夹下文件的数量
[winui3] write an imitation Explorer file manager
Better way to read configuration files than properties
[WinUI3]编写一个仿Explorer文件管理器
MySQL -- execution process and principle of a statement
Manually write smart pointer shared_ PTR function
Innovation training (IX) integration
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
泰克示波器DPO3054自校准SPC失败维修
View analysis of scenic spots in ArcGIS
《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
Machine learning - linear regression
View, modify and delete [database] table
[database] MySQL basic operation (basic operation ~)