Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Normal codes Started Before Ui Code
Forum Updated to NodeBB v4.3 + New Features

Normal codes Started Before Ui Code

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 568 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • faduF Offline
    faduF Offline
    fadu
    wrote on last edited by
    #1

    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 codes

      ui->BtnLogin->setEnabled(false);
       ui->progressBar->setMaximum(0);
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #8

      @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
      }
      
      1 Reply Last reply
      4
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #2

        Hello fadu,

        It is not clear what you would like the forum to do with this piece of information.
        Perhaps you can explain what you are trying to achieve.

        1 Reply Last reply
        2
        • faduF Offline
          faduF Offline
          fadu
          wrote on last edited by
          #3

          @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

          JonBJ 1 Reply Last reply
          0
          • faduF fadu

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @fadu
            That is not the right way to do things. However

            but 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...?

            1 Reply Last reply
            4
            • faduF Offline
              faduF Offline
              fadu
              wrote on last edited by
              #5

              @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

              J.HilkJ 1 Reply Last reply
              0
              • faduF fadu

                @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

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @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


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                3
                • faduF Offline
                  faduF Offline
                  fadu
                  wrote on last edited by
                  #7

                  @J-Hilk

                  void Login::ColorOk()
                  {
                      ui->LblInfo->setStyleSheet("color:green");
                  
                  }
                  The bool signin is came from another class (also no any ui codes in the signin bool)
                  is this the problem
                  
                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ChrisW67
                    wrote on last edited by
                    #8

                    @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
                    }
                    
                    1 Reply Last reply
                    4
                    • faduF Offline
                      faduF Offline
                      fadu
                      wrote on last edited by
                      #9

                      @ChrisW67 Thank You Very Much I Fix It

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved