Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

some problems with qpushbutton->setdisable



  • 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:

    1. I press GPause -> emit signal is ok
    2. qDebug messages is print
    3. the delay is ok ...
    4. I press GRun -> emit signal is ok
    5. qDebug messages is print
    6. for test I try to press GPause immediately after press GRun -> GPause not change BUT
    7. 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


  • Qt Champions 2019

    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.


Log in to reply