简体   繁体   中英

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 )

I was thinking to call different slot and set current_uA = 0 . Looks like it's not possible..

I tried using 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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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