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. QStackedWidget: How to check if the next widget should be shown

QStackedWidget: How to check if the next widget should be shown

Scheduled Pinned Locked Moved Solved General and Desktop
qstackedwidgetqstackedwidgets
25 Posts 4 Posters 3.5k Views
  • 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.
  • JonBJ JonB

    @hobbyProgrammer
    Subject to @J-Hilk suggesting an alternative, as I wrote earlier retain your loginSuccesfull() as the slot for the pushbutton click. Have it emit a signal you define on successful validation of the widgets, the signal is a separate thing from your function which you must define as per the Qt/C++ rules.

    EDIT OK, @J-Hilk's code is the same thing, it's just that he has defined the pushbutton slot as on_pushButton_clicked() and the signal as logInSuccessful, so there is no longer any (non-signal) function named loginSuccesfull().

    H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #16

    @JonB alright, so using that code and these lines:

        LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
        connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
    

    should result in showApp to happen anytime the login was succesfull?

    JonBJ 1 Reply Last reply
    0
    • H hobbyProgrammer

      @JonB alright, so using that code and these lines:

          LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
          connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
      

      should result in showApp to happen anytime the login was succesfull?

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

      @hobbyProgrammer
      I'm hoping so! Did you try it?

      H 1 Reply Last reply
      0
      • JonBJ JonB

        @hobbyProgrammer
        I'm hoping so! Did you try it?

        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #18

        @JonB yes and it didn't work. I tried debugging but I can't seem to find what's going wrong. It hits the code where the emit loginSuccessfull() is set, but it doesn't go to the SLOT where it's connected to and it ends in :

        while (!d->exit.loadAcquire())
                processEvents(flags | WaitForMoreEvents | EventLoopExec);
        
        jsulmJ 1 Reply Last reply
        0
        • H hobbyProgrammer

          @JonB yes and it didn't work. I tried debugging but I can't seem to find what's going wrong. It hits the code where the emit loginSuccessfull() is set, but it doesn't go to the SLOT where it's connected to and it ends in :

          while (!d->exit.loadAcquire())
                  processEvents(flags | WaitForMoreEvents | EventLoopExec);
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #19

          @hobbyProgrammer Did you make sure

          connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
          

          succeeded? And is this "login" the one you're actually showing?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          H 1 Reply Last reply
          1
          • jsulmJ jsulm

            @hobbyProgrammer Did you make sure

            connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
            

            succeeded? And is this "login" the one you're actually showing?

            H Offline
            H Offline
            hobbyProgrammer
            wrote on last edited by
            #20

            @jsulm
            it should be since I'm doing this:

                LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
            
            jsulmJ 1 Reply Last reply
            0
            • H hobbyProgrammer

              @jsulm
              it should be since I'm doing this:

                  LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #21

              @hobbyProgrammer And connect succeeded?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              H 1 Reply Last reply
              1
              • jsulmJ jsulm

                @hobbyProgrammer And connect succeeded?

                H Offline
                H Offline
                hobbyProgrammer
                wrote on last edited by
                #22

                @jsulm I'm not sure, but I don't think so.

                jsulmJ 1 Reply Last reply
                0
                • H hobbyProgrammer

                  @jsulm I'm not sure, but I don't think so.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #23

                  @hobbyProgrammer said in QStackedWidget: How to check if the next widget should be shown:

                  but I don't think so

                  Then it can't work.
                  Use new Qt5 connect syntax to be sure signal/slot are really connected:

                  connect(login, &LoginWidget::loginSuccesfull, this, &MainWindow::showApp);
                  

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  H 1 Reply Last reply
                  2
                  • jsulmJ jsulm

                    @hobbyProgrammer said in QStackedWidget: How to check if the next widget should be shown:

                    but I don't think so

                    Then it can't work.
                    Use new Qt5 connect syntax to be sure signal/slot are really connected:

                    connect(login, &LoginWidget::loginSuccesfull, this, &MainWindow::showApp);
                    
                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on last edited by
                    #24

                    @jsulm yes thank you. That worked!

                    Thank you so much for you patience and help.

                    1 Reply Last reply
                    0
                    • J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #25

                      Because this is getting out of hand:

                      https://github.com/DeiVadder/LoginExample


                      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
                      4

                      • Login

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