当前位置:网站首页>Qt: get sender in slot (the control that triggers signal)
Qt: get sender in slot (the control that triggers signal)
2022-06-09 02:32:00 【Xiaoying Information Technology Service Department】
Qt Development , One scenario is to click three different buttons , Trigger the same event (SLOT), To be in SLOT Method to distinguish three different buttons :
connect(ui->btnType1, SIGNAL(clicked()),this,SLOT(changeType2()));
connect(ui->btnType2, SIGNAL(clicked()),this,SLOT(changeType2()));
connect(ui->btnType3, SIGNAL(clicked()),this,SLOT(changeType2()));
...
void FormCL3P::changeType2()
{
// Get the clicked button
//?
}So how to SLOT Get the current sender Well ? The answer was found on the Internet .
use sender() Method :
void FormCL3P::changeType2()
{
QObject* btn = sender();
if (btn == ui->btnType1){ ... }
if (btn == ui->btnType2){ ... }
if (btn == ui->btnType3){ ... }
}Reference resources :In qml, How can i get signal sender from slot/function? | Qt Forum
边栏推荐
- 贪心法/哈夫曼编码
- Fight the high vision medical service of HKEx again, the gospel of short-sighted partners?
- [suctf 2018]multisql MySQL preprocessing
- 21、ADS使用记录之E类功放设计(中)
- 21. Class E power amplifier design of ads usage record (medium)
- C# 流程控制语句
- Database table cannot add content display modification cannot save prompt 1452 error
- fatal error: juce_ core. h: No such file or directory
- [wustctf 2020] plain
- 20、ADS使用记录之E类功放设计(上)
猜你喜欢

Processes and threads

C# 基础篇

Kubernetes scheduling framework extension point

Using redis in business code to achieve caching effect

【HomeAssistant外网访问(cpolar)】

Redis cluster setup

Indonesia widya robotics and Huawei cloud make the safety of construction sites visible

Embracing out of hospital prescription drugs, Internet medicine should also "get rid of virtual reality"?

20. Class E power amplifier design for ads usage record (Part 1)

2022.6 download and installation tutorial of the latest version of mongodb
随机推荐
Navicat tool batch imports JSON format data to Doris
Acwing 792 high precision subtraction
fatal error: juce_ core. h: No such file or directory
杰理之若用户不需要使用所有的按键,其他按键应该如何设置?【篇】
Classify the audio and put it into the corresponding folder according to the file name
Binary tree chain structure
Blue Bridge Cup_ Diophantine equation
C# 类和对象
What is the hardware calculation principle of Jerry's ad value? [chapter]
pkg-config --modversion opencvPackage opencv was not found in the pkg-config search path. Perhaps y
How to implement the project practice of user registration, login and logout in flask + MySQL
2022年信息安全工程师考试知识点:网络安全产品的配置与使用
【网络协议】| 【01】网络字节序大端、小端
Should flying books be ecological? Analyze the first independent SaaS case of all in flybook
Tiflash source code reading (III) design and implementation analysis of tiflash deltatree storage engine - Part 1
Read the log + regularize and extract the desired content + write the script to csv/xlsx
[SUCTF 2019]EasyWeb
在业务代码中使用redis实现缓存效果
CVE-2022-30525漏洞複現
力扣解法汇总1037-有效的回旋镖