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. How to detect page change in QWizard?
Forum Updated to NodeBB v4.3 + New Features

How to detect page change in QWizard?

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 796 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.
  • M Mads030306

    How can i detect a next button click or page change?

    Here is my code:
    #include <QtWidgets>
    #include <QTranslator>
    #include <QLocale>
    #include <QLibraryInfo>
    #include <iostream>

    QWizardPage *createIntroPage()
    {
    QWizardPage *page = new QWizardPage;
    page->setTitle("Transporter Addon");

    QLabel *label = new QLabel("Denne installer vil installer Transporter Addon for dig.");
    label->setWordWrap(true);
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(label);
    page->setLayout(layout);
    
    return page;
    

    }

    QWizardPage *createInstallPage()

    {

    QWizardPage *page = new QWizardPage;
    page->setTitle("Installere");
    page->setSubTitle("Klik install for at instalere Transporter Addon");
    
    page->setButtonText(QWizard::NextButton, "Install");
    
    return page;
    

    }

    QWizardPage *createInstallingPage()

    {

    QWizardPage *page = new QWizardPage;
    page->setTitle("Installere");
    page->setSubTitle("Klik install for at instalere Transporter Addon");
    
    QProgressBar *bar = new QProgressBar();
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(bar);
    page->setLayout(layout);
    
    page->setButtonText(QWizard::NextButton, "Install");
    
    
    
    return page;
    

    }

    QWizardPage *createDonePage()

    {

    QWizardPage *page = new QWizardPage;
    page->setTitle("Conclusion");
    
    QLabel *label = new QLabel("You are now successfully registered. Have a "
                               "nice day!");
    label->setWordWrap(true);
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(label);
    page->setLayout(layout);
    
    return page;
    

    }

    class Handler : public QObject
    {
    Q_OBJECT

    public slots:
        void next(){
            std::cout << "Debug";
        }
    

    };

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    #ifndef QT_NO_TRANSLATION
    QString translatorFileName = QLatin1String("qtbase_");
    translatorFileName += QLocale::system().name();
    QTranslator *translator = new QTranslator(&app);
    if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
    app.installTranslator(translator);
    #endif

    QWizard wizard;
    wizard.addPage(createIntroPage());
    wizard.addPage(createInstallPage());
    wizard.addPage(createInstallingPage());
    wizard.addPage(createDonePage());
    
    
    Handler handler;
    
    wizard.setWindowTitle("Transporter Addon Installer");
    wizard.show();
    
    return app.exec();
    

    }

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

    @Mads030306 said in How to detect page change in QWizard?:

    How can i detect a next button click or page change?

    Hello and welcome.

    void QWizard::currentIdChanged(int id)

    This signal is emitted when the current page changes, with the new current id.

    ?

    1 Reply Last reply
    1
    • M Offline
      M Offline
      Mads030306
      wrote on last edited by
      #3

      Thanks.

      I already tried using that signal but couldn't get it to work.

      Which object is the sender and how do i create a slot?

      JonBJ 1 Reply Last reply
      0
      • M Mads030306

        Thanks.

        I already tried using that signal but couldn't get it to work.

        Which object is the sender and how do i create a slot?

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

        @Mads030306 said in How to detect page change in QWizard?:

        I already tried using that signal but couldn't get it to work.

        Then show your code. "couldn't get it to work" might mean wouldn't compile, didn't connect() successfully, ran and called the slot but whatever you did in the slot didn't work or never called the slot.

        Which object is the sender and how do i create a slot?

        The QWizard is the sender and you would create a slot for it like any slot for a signal. Let's see what you attempted. (Just for this bit, not your whole program!)

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Mads030306
          wrote on last edited by Mads030306
          #5
          class Handler : public QObject
          {
              Q_OBJECT
          
              public slots:
                  void next();
          };
          
          
          
          void Handler::next(){
              std::cout << "Debug";
          }
          
              //this is in my main function
              Handler /***/handler/* = new Handler()*/;
          
              wizard.connect(&wizard, SIGNAL ( QWizard::currentIdChanged(int) ), &handler, SLOT ( Handler::next ));
          

          6ca8d350-d27a-4b8f-a272-65f466ce0964-billede.png

          jsulmJ JonBJ 2 Replies Last reply
          0
          • M Mads030306
            class Handler : public QObject
            {
                Q_OBJECT
            
                public slots:
                    void next();
            };
            
            
            
            void Handler::next(){
                std::cout << "Debug";
            }
            
                //this is in my main function
                Handler /***/handler/* = new Handler()*/;
            
                wizard.connect(&wizard, SIGNAL ( QWizard::currentIdChanged(int) ), &handler, SLOT ( Handler::next ));
            

            6ca8d350-d27a-4b8f-a272-65f466ce0964-billede.png

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

            @Mads030306 Please be more specific: did you put your Handler class in its own header/cpp files?

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

            1 Reply Last reply
            1
            • M Mads030306
              class Handler : public QObject
              {
                  Q_OBJECT
              
                  public slots:
                      void next();
              };
              
              
              
              void Handler::next(){
                  std::cout << "Debug";
              }
              
                  //this is in my main function
                  Handler /***/handler/* = new Handler()*/;
              
                  wizard.connect(&wizard, SIGNAL ( QWizard::currentIdChanged(int) ), &handler, SLOT ( Handler::next ));
              

              6ca8d350-d27a-4b8f-a272-65f466ce0964-billede.png

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

              @Mads030306 said in How to detect page change in QWizard?:

              wizard.connect(&wizard, SIGNAL ( QWizard::currentIdChanged(int) ), &handler, SLOT ( Handler::next ));

              Your syntax is wrong. Please, please change over to New Signal Slot Syntax --- which has been around for years ever since Qt5 --- and it will stop you doing this. Get rid of all SIGNAL/SLOT() macros. Life will be so much easier/cleaner.

              I could tell you what you need in old style but it would be much better for you if you change over, so do that first....

              M 1 Reply Last reply
              1
              • JonBJ JonB

                @Mads030306 said in How to detect page change in QWizard?:

                wizard.connect(&wizard, SIGNAL ( QWizard::currentIdChanged(int) ), &handler, SLOT ( Handler::next ));

                Your syntax is wrong. Please, please change over to New Signal Slot Syntax --- which has been around for years ever since Qt5 --- and it will stop you doing this. Get rid of all SIGNAL/SLOT() macros. Life will be so much easier/cleaner.

                I could tell you what you need in old style but it would be much better for you if you change over, so do that first....

                M Offline
                M Offline
                Mads030306
                wrote on last edited by
                #8

                @JonB
                I have changed to the new method but still get the same error.

                wizard.connect(&wizard, &QWizard::currentIdChanged, &handler, &Handler::next);
                

                Do i have to specify the parameter of &QWizard::currentIdChanged like before (SIGNAL ( QWizard::currentIdChanged(int) ))?

                JonBJ 1 Reply Last reply
                0
                • M Mads030306

                  @JonB
                  I have changed to the new method but still get the same error.

                  wizard.connect(&wizard, &QWizard::currentIdChanged, &handler, &Handler::next);
                  

                  Do i have to specify the parameter of &QWizard::currentIdChanged like before (SIGNAL ( QWizard::currentIdChanged(int) ))?

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

                  @Mads030306
                  OK, that new syntax is a big improvement!

                  With that for " still get the same error" do you still get that error which is a linker error or do you get a compiler error? If it's a compiler error, it's not "the same" (in which case please show the new error message).

                  Depending on answer, it looks like you are not linking with the module for Handler....

                  Do i have to specify the parameter of &QWizard::currentIdChanged like before (SIGNAL ( QWizard::currentIdChanged(int) ))?

                  No. Rather the signature for slot Handler::next(...) must "match" the signature for signal QWizard::currentIdChanged(). Show your signature for Handler::next(...) definition if not sure.

                  M 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @Mads030306
                    OK, that new syntax is a big improvement!

                    With that for " still get the same error" do you still get that error which is a linker error or do you get a compiler error? If it's a compiler error, it's not "the same" (in which case please show the new error message).

                    Depending on answer, it looks like you are not linking with the module for Handler....

                    Do i have to specify the parameter of &QWizard::currentIdChanged like before (SIGNAL ( QWizard::currentIdChanged(int) ))?

                    No. Rather the signature for slot Handler::next(...) must "match" the signature for signal QWizard::currentIdChanged(). Show your signature for Handler::next(...) definition if not sure.

                    M Offline
                    M Offline
                    Mads030306
                    wrote on last edited by
                    #10

                    @JonB
                    i get a compile error (the one in the picture in the other post).

                    On the signal and slots documentation i found something about the error i get, i need to run something called moc but i dont know how to run it.

                    The Q_OBJECT macro is expanded by the preprocessor to declare several member functions that are implemented by the moc; if you get compiler errors along the lines of "undefined reference to vtable for LcdNumber", you have probably forgotten to run the moc or to include the moc output in the link command.
                    

                    Also what is linking and how do i do it.

                    JonBJ 1 Reply Last reply
                    0
                    • M Mads030306

                      @JonB
                      i get a compile error (the one in the picture in the other post).

                      On the signal and slots documentation i found something about the error i get, i need to run something called moc but i dont know how to run it.

                      The Q_OBJECT macro is expanded by the preprocessor to declare several member functions that are implemented by the moc; if you get compiler errors along the lines of "undefined reference to vtable for LcdNumber", you have probably forgotten to run the moc or to include the moc output in the link command.
                      

                      Also what is linking and how do i do it.

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

                      @Mads030306 said in How to detect page change in QWizard?:

                      i need to run something called moc but i dont know how to run it.

                      Also what is linking and how do i do it.

                      All this is done for you by the build process, assuming your project is correctly defined in the .pro file.

                      • Show your signature for Handler::next(...). Also confirm in the .h file it is in section public slots:. I need to check that anyway.
                      • Show your declaration of class Handler. Since it is using signals/slots, does it have a line reading just Q_OBJECT immediately after the { of the class declaration in the .h file?

                      (Essentially just show the whole of the class Handler declaration in the .h [not .cpp!] file.)

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        Mads030306
                        wrote on last edited by
                        #12

                        I dont have a header file, i only have the folowing code and it is in the main cpp file.

                        class Handler : public QObject
                        {
                            Q_OBJECT
                        
                            public slots:
                                void next();
                        };
                        
                        
                        
                        void Handler::next(){
                            std::cout << "Debug";
                        }
                        

                        Do i have to move my class into a header file and include that header?

                        jsulmJ JonBJ 2 Replies Last reply
                        0
                        • M Mads030306

                          I dont have a header file, i only have the folowing code and it is in the main cpp file.

                          class Handler : public QObject
                          {
                              Q_OBJECT
                          
                              public slots:
                                  void next();
                          };
                          
                          
                          
                          void Handler::next(){
                              std::cout << "Debug";
                          }
                          

                          Do i have to move my class into a header file and include that header?

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

                          @Mads030306 said in How to detect page change in QWizard?:

                          I dont have a header file, i only have the folowing code and it is in the main cpp file

                          Please move your Handler class in its own header and cpp files! Classes which subclass QObject needs to be in their own header/cpp files in order for moc to be able to process them.

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

                          1 Reply Last reply
                          2
                          • M Mads030306

                            I dont have a header file, i only have the folowing code and it is in the main cpp file.

                            class Handler : public QObject
                            {
                                Q_OBJECT
                            
                                public slots:
                                    void next();
                            };
                            
                            
                            
                            void Handler::next(){
                                std::cout << "Debug";
                            }
                            

                            Do i have to move my class into a header file and include that header?

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

                            @Mads030306 said in How to detect page change in QWizard?:

                            Do i have to move my class into a header file and include that header?

                            Not necessarily, unless we find that moc does not like multiple classes with Q_OBJECT in them in one source file or only likes them in a .h file, which I do not know....

                            Can we confirm that this class Handler you show is placed in the source file above/before the compiler meets the wizard.connect(&wizard, &QWizard::currentIdChanged, &handler, &Handler::next); line?

                            UPDATE
                            According to e.g. https://forum.qt.io/topic/12388/q_object-in-cpp-file we are not going to do well with Q_OBJECT class in a .cpp file. By far the simplest will be to split it:

                            • Create a new handler.cpp & handler.h file in your project (from the Qt Creator wizard which allows you to add a new class-file, so that the .pro gets updated right).
                            • Move your Handler definition code into the .cpp.
                            • Move your Handler declaration code into the .h.
                            • Do a complete qmake/rebuild, and see what you get.

                            When that is working you will want to change your Handler::next() slot to accept the int id parameter that QWizard::currentIdChanged(int id) will be passing to it. From that you will be able to find out about which page change is happening.

                            1 Reply Last reply
                            1
                            • M Offline
                              M Offline
                              Mads030306
                              wrote on last edited by
                              #15

                              It works now.

                              Thank you for helping :)

                              Sorry for my dumb questions, im very new to c++ and qt.

                              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