Unsolved How to use two or three button's logic in single button using CPP in QT
-
@presstab The problem is those timers. The functions should be turned into slots. Then the methods need to be chained as each one completes. The asynchronous nature of each function makes this complicated.
-
@fcarney correct. Overall the code isn't fantastic. Looking at it, I don't see why there would be any purpose of running A at all if immediately running B and C after (although not totally sure since we don't have that code) . Although cleaning up the code completely is always the best, this would likely still accomplish the goal.
MyWidget::DoB(bool fRunC) { ui->label_lastCommand->setText("Last command: Beep"); ui->progressBar->setMaximum(UPDATE_FREQUENCY * (ui->doubleSpinBox_general->value() + 122)); pJMPX->RDS_Set_11A_Enable(true); progressTimer->start(); QTimer::singleShot(122000, this, [this](){ pJMPX->RDS_Set_11A_data(0x0008, 0x0000); if (fRunC) DoC(); }); } MyWidget::NameOfYourSlot() { if(ui->radioButton_wake->isChecked()) // Button A { DoA(); } else if(ui->radioButton_beep->isChecked()) // Button B { DoB(/*fRunC*/false); } else if(ui->radioButton_beginPlayback->isChecked()) // Button c { DoC(); } else if(ui->radioButton->isChecked()) { DoB(/*fRunC*/true); }
-
@presstab said in How to use two or three button's logic in single button using CPP in QT:
DoB(/fRunC/true);
Thanks for the response, I have used same logic and getting the error " Variable 'fRunC' cannot be implicitly captured in a lambda with no capture-default specified". Could you please resolve the issue
-
@reddipradeep-embd said in How to use two or three button's logic in single button using CPP in QT:
cannot be implicitly captured in a lambda
-
QTimer::singleShot(122000, this, [fRunC](){ pJMPX->RDS_Set_11A_data(0x0008, 0x0000); if (fRunC) DoC(); });
-
@presstab I was trying to lead the op to water.
-
@presstab Hi, Sorry to bother you again, I have modified the code accordingly and getting the error in he below code " mainwindow.cpp:305:9: error: 'this' cannot be implicitly captured in this context "
QTimer::singleShot(122000, this, fRunC{
pJMPX->RDS_Set_11A_data(0x0008, 0x0000);
if (fRunC)
DoC();
}); -
QTimer::singleShot(122000, this, fRunC{
Why do you use
fRunC
where the code to copy uses[fRunC]()
?EDIT LOL, I just realised, I guess
[fRunC]()
comes out looking like fRunC on this forum if you don't
Code
tags it :) -
@reddipradeep-embd You are close, keep playing around with it until you get it to work.
-
Hi
What does the singleShot actually do ?QTimer::singleShot(122000, this, this{
pJMPX->RDS_Set_11A_data(0x0008, 0x0000);
});does it have to wait 12200 ms after calling
pJMPX->RDS_Set_11A_Enable(true);or why this design ?