some problems with qpushbutton->setdisable
Unsolved
General and Desktop
-
I use setdisable true/false for "close" mouse event over a button after the User pressed action. I use a delay for renew the condition aver qpushbutton .... my simple code:
void MainWindow::sendPause(bool paGen) { ui->GRun->setDisabled(true); if (paGen && (StIsOn1 && StIsRunning1)) { qDebug() << "xxxxx1"; ui->Grun->setChecked(false); emit sendInOut(k::cm_pause_gen, true, 0); } else{ qDebug() << "xxxxx2"; ui->GPause->setChecked(false); } PauseResumeAutocheck(); } void MainWindow::sendRun(bool paRun) { ui->Grun->setDisabled(true); if (paRun && (StIsOn1x && StIsRunning1x)) { qDebug() << "xxxxx3"; ui->GPause->setChecked(false); emit sendInOut(k::cm_pause_gen, false, 0); } else{ qDebug() << "xxxxx4"; ui->GRun->setChecked(false); } PauseResumeAutocheck(); } void MainWindow::PauseResumeAutocheck() { QTimer::singleShot(1200, [=]{ ui->Grun->setDisabled(false); ui->Gpause->setDisabled(false); qDebug() << "reset Pause Resume";}); }
The two qpushbutton is insert in a qgrouobox, and I set it as Autoexclusive.
The code work not so good (some time the delay is not see) ... any how the event is equally propagated ... for example:
- I press GPause -> emit signal is ok
- qDebug messages is print
- the delay is ok ...
- I press GRun -> emit signal is ok
- qDebug messages is print
- for test I try to press GPause immediately after press GRun -> GPause not change BUT
- qDebug messages is print ... ????? Why these?????
I hope someone can suggest my the right process to do these, because this obviuslly is not perfect working.
regards
Giorgio -
You use QTimer::singleShot - it is executed every time and you can't stop it from executing. Just use a QTimer object to have more control over it.