[英]Widget cant send signal if it is disabled
I have a basic question我有一个基本问题
There is a pushbutton to enable a widget as follows:有一个按钮可以启用小部件,如下所示:
connect(ui->pushButton_currOnOne, &QPushButton::clicked, ui->widget_currentOne, &CurrentButtonOne::setEnabled);
and this widget is connected to a slot to adjust a value:并且此小部件连接到插槽以调整值:
connect(ui->widget_currentOne, &CurrentButtonOne::getValue, this, &stageProgram::setCurrOnChannelOne);
and the slot is:插槽是:
void stageProgram::setCurrOnChannelOne(unsigned int current_uA)
{
tetra_grip_api::stimulation_set_current( m_channelOne, current_uA); // second argument I get as signal from the widget
}
But what I now need if the widget is disabled the signal value should be 0
(meaning the current_uA = 0
)但是如果小部件被禁用,我现在需要的信号值应该是
0
(意味着current_uA = 0
)
I was thinking to call different slot and set current_uA = 0
.我正在考虑调用不同的插槽并设置
current_uA = 0
。 Looks like it's not possible..看来不可能了。。
I tried using Lambda我尝试使用Lambda
connect(ui->widget_currentOne, &CurrentButtonOne::getValue,
[this](unsigned int current_uA) { setCurrOnChannelOne(ui->widget_currentOne->isEnabled() ? current_uA : 0); } );
//this does not send 0 when it is disabled
can you suggest a way to send zero signal when the widget is disabled?您能建议一种在禁用小部件时发送零信号的方法吗?
I think its better to define the following slot for the CurrentButtonOne
:我认为最好为
CurrentButtonOne
定义以下插槽:
void disableMe() {
//Disable
setDisabled(true);
//Reset current_uA
current_uA = 0;
}
and then connect the signals and slots as follows:然后按如下方式连接信号和插槽:
connect(ui->pushButton_currOnOne, &QPushButton::clicked, ui->widget_currentOne, &CurrentButtonOne::disableMe);
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.