繁体   English   中英

如果禁用,小部件无法发送信号

[英]Widget cant send signal if it is disabled

我有一个基本问题

有一个按钮可以启用小部件,如下所示:

connect(ui->pushButton_currOnOne, &QPushButton::clicked, ui->widget_currentOne, &CurrentButtonOne::setEnabled);

并且此小部件连接到插槽以调整值:

 connect(ui->widget_currentOne, &CurrentButtonOne::getValue, this, &stageProgram::setCurrOnChannelOne);

插槽是:

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
}

但是如果小部件被禁用,我现在需要的信号值应该是0 (意味着current_uA = 0

我正在考虑调用不同的插槽并设置current_uA = 0 看来不可能了。。

我尝试使用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

您能建议一种在禁用小部件时发送零信号的方法吗?

我认为最好为CurrentButtonOne定义以下插槽:

void disableMe() {

    //Disable
    setDisabled(true);

    //Reset current_uA
    current_uA = 0;
}

然后按如下方式连接信号和插槽:

connect(ui->pushButton_currOnOne, &QPushButton::clicked, ui->widget_currentOne, &CurrentButtonOne::disableMe);

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM