Normal codes Started Before Ui Code
-
when i try this codes
void Login::on_BtnLogin_clicked() { ui->BtnLogin->setEnabled(false); ui->progressBar->setMaximum(0); if(s.SignIn(ui->TxtUser->text(),ui->TxtPass->text(),Seria.remove("SN : "))) { QString abc = ui->TxtUser->text(); ColorOk(); ui->LblInfo->setText("Welcome {" + abc +"} Login Success"); } else { if(s.errorcode == 1) { ColorError(); ui->LblInfo->setText("Invalid User Or Pass"); } }
it's excute if(s.SignIn(ui->TxtUser->text(),ui->TxtPass->text(),Seria.remove("SN : ")))
and when finish all codes inside if start this codesui->BtnLogin->setEnabled(false); ui->progressBar->setMaximum(0);
-
@fadu While the slot is running there are no updates to the GUI, so there will be not be a visible change of the button to disabled and back to enable appearance. There should be nothing long running in these slots warranting disabling a button. @J-Hilk and I suspect that there is a long running process, and this would appear to be the s.SignIn() call.
If the SignIn() call is a network or database event and it is coded using Qt classes, then it should be asynchronous and emitting a signal to carry the success/failure of the sign-in. If that is the case then you should aim for something like:
void Login::on_BtnLogin_clicked() { // disable the button // start the SignIn // exit the slot } void on_SignInResult(int errorCode ) { // connected to the "s" object if (errorCode == SUCCESS) { QString abc = ui->TxtUser->text(); ColorOk(); ui->LblInfo->setText("Welcome {" + abc +"} Login Success"); } else { // FAILED ColorError(); ui->LblInfo->setText("Invalid User Or Pass"); } // enable the button }
-
@ChrisW67
i want to block user from press button until finish all codes inside bool Sign
but the result is the button disabled after bool sign finish all codes@fadu
That is not the right way to do things. Howeverbut the result is the button disabled after bool sign finish all codes
Since you go
ui->BtnLogin->setEnabled(false);
and never restore
ui->BtnLogin->setEnabled(true);
what do you expect? Surely I must be misunderstanding...?
-
@JonB
first i added restore code in the final of sign
but i removed it for test
also the main problem disable button code didn't work until sign finished@fadu
right, because you're not doing it not the way you're supposed to.You have to give the Qt EventLoop opportunity to change the ui.
By doing everything inside one function call, the event loop is not running -> no update of the ui
also I'm pretty sure your
ColorOk();
has either a long task or infinite loop in it, am I right ?Also bad design for an event driven system like Qt
-
@fadu While the slot is running there are no updates to the GUI, so there will be not be a visible change of the button to disabled and back to enable appearance. There should be nothing long running in these slots warranting disabling a button. @J-Hilk and I suspect that there is a long running process, and this would appear to be the s.SignIn() call.
If the SignIn() call is a network or database event and it is coded using Qt classes, then it should be asynchronous and emitting a signal to carry the success/failure of the sign-in. If that is the case then you should aim for something like:
void Login::on_BtnLogin_clicked() { // disable the button // start the SignIn // exit the slot } void on_SignInResult(int errorCode ) { // connected to the "s" object if (errorCode == SUCCESS) { QString abc = ui->TxtUser->text(); ColorOk(); ui->LblInfo->setText("Welcome {" + abc +"} Login Success"); } else { // FAILED ColorError(); ui->LblInfo->setText("Invalid User Or Pass"); } // enable the button }