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. Connecting QPushButton of QWizardPage with NextButton of QWizard!
Forum Updated to NodeBB v4.3 + New Features

Connecting QPushButton of QWizardPage with NextButton of QWizard!

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.8k Views 2 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.
  • P Offline
    P Offline
    Pedro_Monteiro
    wrote on last edited by
    #1

    Hi, how could I connect a QPushButton of a QWizardPage with the Next Button of Qwizard?
    What I want is: when I click in the QPushButton created in the QWizardPage, the page goes to the next screen.
    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      there is void QWizard::next() slot
      so you can connect buttons clicked to that.

      P 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        there is void QWizard::next() slot
        so you can connect buttons clicked to that.

        P Offline
        P Offline
        Pedro_Monteiro
        wrote on last edited by Pedro_Monteiro
        #3

        @mrjj How could I use QWizard::next() inside a QWizardPage?
        Is there any example?

        mrjjM 1 Reply Last reply
        0
        • P Pedro_Monteiro

          @mrjj How could I use QWizard::next() inside a QWizardPage?
          Is there any example?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Pedro_Monteiro
          its a slot so u just send signal to by binding it to the signal a button gives.

          connect( Wizpage->pushButton, SIGNAL(released()), QWizardPointer, SLOT(next()));

          Maybe you need to connect it where you create the wizpages as there it both knows the button and the Wizard.

          A 1 Reply Last reply
          0
          • mrjjM mrjj

            @Pedro_Monteiro
            its a slot so u just send signal to by binding it to the signal a button gives.

            connect( Wizpage->pushButton, SIGNAL(released()), QWizardPointer, SLOT(next()));

            Maybe you need to connect it where you create the wizpages as there it both knows the button and the Wizard.

            A Offline
            A Offline
            AhmedAlshawi
            wrote on last edited by
            #5

            @mrjj said in Connecting QPushButton of QWizardPage with NextButton of QWizard!:

            @Pedro_Monteiro
            its a slot so u just send signal to by binding it to the signal a button gives.

            connect( Wizpage->pushButton, SIGNAL(released()), QWizardPointer, SLOT(next()));

            Maybe you need to connect it where you create the wizpages as there it both knows the button and the Wizard.

            @mrjj I can't seem to get this to work :(

            Would you be able to help with the correct 'connect' line?
            I've current got:

            connect(button, SIGNAL(pressed()), &myWizard, SLOT(next()));
            

            Here is the code:

            From my myWizard.cpp

            myWizard::myWizard(QWidget *parent)
                : QWizard(parent)
            {
                setPage(Page_Intro, new IntroPage);
                setPage(Page_1, new firstPage);
                setPage(Page_2, new secondPage);
            
                setStartId(Page_Intro);
            
            #ifndef Q_OS_MAC
                setWizardStyle(ModernStyle);
            #endif
            
                setOption(HaveHelpButton, true);
                setPixmap(QWizard::LogoPixmap, QPixmap(":/img/logo.png"));
                connect(this, &QWizard::helpRequested, this, &myWizard::showHelp);
                setWindowTitle(tr("This is my wizard"));
            }
            
            firstPage::firstPage(QWidget *parent)
                : QWizardPage(parent)
            {
                setTitle(tr("This is my first page"));
                setSubTitle(tr("Select from the options below"));
            
                list = new QListWidget();
            
                item0 = new QListWidgetItem(QStringLiteral("Item 0"));
            
                item1 = new QListWidgetItem(QStringLiteral("Item 1"));
            
                item2 = new QListWidgetItem(QStringLiteral("Item 2"));
            
                list->addItem(item0);
                list->addItem(item1);
                list->addItem(item2);
            
                listDescription = new QLabel();
                listDescription->setWordWrap(true);
            
                button = new QPushButton("My Button");
                buttonPressed= false;
            
                connect(list, SIGNAL(currentRowChanged(int)), this, SLOT(changeDescription(int)));
            
            //***************************TRYING TO GET THIS RIGHT****************************************
                connect(button, SIGNAL(pressed()), &myWizard, SLOT(next()));
            //*******************************************************************************************
            
                QGridLayout *layout = new QGridLayout;
                layout->addWidget(list, 0,0);
                layout->addWidget(listDescription, 0, 1, Qt::AlignTop);
                layout->addWidget(button, 1,1);
                layout->setColumnStretch(0,1);
                layout->setColumnStretch(1,1);
                setLayout(layout);
            
                connect(list, SIGNAL(itemSelectionChanged()), this, SIGNAL(completeChanged()));
            }
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi

              Hi
              About
              connect(button, SIGNAL(pressed()), &myWizard, SLOT(next()));

              What is the issue do you get a error ?
              Is myWizard a member firstPage ?
              It has to be the actual QWizard you have on MainWindow and not a new one.

              Or is that the actual issue?
              You are unsure how to connect to the
              https://doc.qt.io/qt-5/qwizard.html#next ?

              Well if you give it the QWizard as a parent in
              FirstPage(QWidget *parent)
              When you are inside pages, you could do

              QWizard *wiz=qobject_cast<QWizard *> (parentWidget());

              and then do
              bool worked=connect(button, SIGNAL(pressed()), wiz, SLOT(next()));
              qDebug() << "it worked:" << worked;

              which will work If the parent is the QWizard.

              You can also define some pr signals for the page that you can emit from inside the page to go back and forth.

              A 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi

                Hi
                About
                connect(button, SIGNAL(pressed()), &myWizard, SLOT(next()));

                What is the issue do you get a error ?
                Is myWizard a member firstPage ?
                It has to be the actual QWizard you have on MainWindow and not a new one.

                Or is that the actual issue?
                You are unsure how to connect to the
                https://doc.qt.io/qt-5/qwizard.html#next ?

                Well if you give it the QWizard as a parent in
                FirstPage(QWidget *parent)
                When you are inside pages, you could do

                QWizard *wiz=qobject_cast<QWizard *> (parentWidget());

                and then do
                bool worked=connect(button, SIGNAL(pressed()), wiz, SLOT(next()));
                qDebug() << "it worked:" << worked;

                which will work If the parent is the QWizard.

                You can also define some pr signals for the page that you can emit from inside the page to go back and forth.

                A Offline
                A Offline
                AhmedAlshawi
                wrote on last edited by
                #7

                @mrjj

                Thanks for the fast reply! Yes exactly, I am unsure how to connect a button press on my wizard page to my QWizard's next slot. My current connect statement says "error: 'myWizard' does not refer to a value"

                I tried your suggestion, but it didn't work either. I get this error:
                "QObject::connect: Cannot connect QPushButton::pressed() to (nullptr)::next()"
                I suspect I haven't allocated the parent correctly maybe?

                I also dont understand what you mean by: "Is myWizard a member firstPage ?"

                Maybe it will help if I explain what I'm trying to do. I'm setting up a wizard which will have multiple pages. On one of the pages, it will include a pushbutton. If that pushbutton is clicked, I want it to take me to a side page which only has the back button enabled. The flow would be something like below, with the pushbutton being on Page 3, which takes me to Side_Page.

                Page 1 
                  ↓
                Page 2
                  ↓
                Page 3 (pushbutton on this page) ←→ Side_Page
                  ↓
                Page 4
                  ↓
                Page 5 
                  ↓
                ....etc
                

                I though that if I get the pushbutton connected to the wizard's next(), then in the nextId(), I could check if the button was pressed (not figured out how to do that yet), and return Page 4 if the button was not pressed, but return Side_Page if the button was pressed.

                Maybe there is a better way to achieve this?

                mrjjM 1 Reply Last reply
                0
                • A AhmedAlshawi

                  @mrjj

                  Thanks for the fast reply! Yes exactly, I am unsure how to connect a button press on my wizard page to my QWizard's next slot. My current connect statement says "error: 'myWizard' does not refer to a value"

                  I tried your suggestion, but it didn't work either. I get this error:
                  "QObject::connect: Cannot connect QPushButton::pressed() to (nullptr)::next()"
                  I suspect I haven't allocated the parent correctly maybe?

                  I also dont understand what you mean by: "Is myWizard a member firstPage ?"

                  Maybe it will help if I explain what I'm trying to do. I'm setting up a wizard which will have multiple pages. On one of the pages, it will include a pushbutton. If that pushbutton is clicked, I want it to take me to a side page which only has the back button enabled. The flow would be something like below, with the pushbutton being on Page 3, which takes me to Side_Page.

                  Page 1 
                    ↓
                  Page 2
                    ↓
                  Page 3 (pushbutton on this page) ←→ Side_Page
                    ↓
                  Page 4
                    ↓
                  Page 5 
                    ↓
                  ....etc
                  

                  I though that if I get the pushbutton connected to the wizard's next(), then in the nextId(), I could check if the button was pressed (not figured out how to do that yet), and return Page 4 if the button was not pressed, but return Side_Page if the button was pressed.

                  Maybe there is a better way to achieve this?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  Hi

                  I tried your suggestion, but it didn't work either. I get this error:
                  "QObject::connect: Cannot connect QPushButton::pressed() to (nullptr)::next()"
                  I suspect I haven't allocated the parent correctly maybe?

                  Update: To future readers. One can use wizard() inside "Pages" so please see later post.

                  Well it means the parent is not a QWizard,
                  when you do
                  firstPage * fp = new firstPage(this); <<< the this is the parent
                  so I had hoped it would be the actual QWizard instance.
                  By instance, i mean where you do
                  myWizard * mw= myWizard();
                  The myWizard is the one you need for connection.
                  But since you want to connect inside the pages, we need access to this pointer.

                  but i think this creates the pages , right ?

                  Could you try

                  setPage(Page_Intro, new IntroPage(myWizard ));
                  so it get the actual QWizrd as parent ?
                  (for all pages)

                  Maybe it will help if I explain what I'm trying to do. I'm setting up a wizard which will have multiple pages. On one of the pages, it will include a pushbutton. If that pushbutton is clicked, I want it to take me to a side page which only has the back button enabled. The flow would be something like below, with the pushbutton being on Page 3, which takes me to Side_Page.

                  Ok. so this side page is outside of the main flow ? so to speak.

                  I though that if I get the pushbutton connected to the wizard's next(), then in the nextId(), I could check if the button was pressed (not figured out how to do that yet), and return Page 4 if the button was not pressed, but return Side_Page if the button was pressed.

                  Maybe there is a better way to achieve this?

                  Well using nextId sounds good. but the part of knowing if the button was clicked, will require a variable to keep track of that.

                  You could also just define a new signal ( in that page class)
                  signals:
                  void GotoSidePage();

                  and connect that to a slot in myWizard, that actually set the page to this side page.

                  and for the (pushbutton on this page), you connect to a slot that does

                  emit GotoSidePage();

                  Then myWizard can just show that page.

                  A 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    Hi

                    I tried your suggestion, but it didn't work either. I get this error:
                    "QObject::connect: Cannot connect QPushButton::pressed() to (nullptr)::next()"
                    I suspect I haven't allocated the parent correctly maybe?

                    Update: To future readers. One can use wizard() inside "Pages" so please see later post.

                    Well it means the parent is not a QWizard,
                    when you do
                    firstPage * fp = new firstPage(this); <<< the this is the parent
                    so I had hoped it would be the actual QWizard instance.
                    By instance, i mean where you do
                    myWizard * mw= myWizard();
                    The myWizard is the one you need for connection.
                    But since you want to connect inside the pages, we need access to this pointer.

                    but i think this creates the pages , right ?

                    Could you try

                    setPage(Page_Intro, new IntroPage(myWizard ));
                    so it get the actual QWizrd as parent ?
                    (for all pages)

                    Maybe it will help if I explain what I'm trying to do. I'm setting up a wizard which will have multiple pages. On one of the pages, it will include a pushbutton. If that pushbutton is clicked, I want it to take me to a side page which only has the back button enabled. The flow would be something like below, with the pushbutton being on Page 3, which takes me to Side_Page.

                    Ok. so this side page is outside of the main flow ? so to speak.

                    I though that if I get the pushbutton connected to the wizard's next(), then in the nextId(), I could check if the button was pressed (not figured out how to do that yet), and return Page 4 if the button was not pressed, but return Side_Page if the button was pressed.

                    Maybe there is a better way to achieve this?

                    Well using nextId sounds good. but the part of knowing if the button was clicked, will require a variable to keep track of that.

                    You could also just define a new signal ( in that page class)
                    signals:
                    void GotoSidePage();

                    and connect that to a slot in myWizard, that actually set the page to this side page.

                    and for the (pushbutton on this page), you connect to a slot that does

                    emit GotoSidePage();

                    Then myWizard can just show that page.

                    A Offline
                    A Offline
                    AhmedAlshawi
                    wrote on last edited by
                    #9

                    Could you try

                    setPage(Page_Intro, new IntroPage(myWizard ));
                    so it get the actual QWizrd as parent ?
                    (for all pages)

                    This doesn't work :(
                    It gives me "error: 'myWizard' does not refer to a value"

                    Ok. so this side page is outside of the main flow ? so to speak.

                    Yes exactly!

                    I though that if I get the pushbutton connected to the wizard's next(), then in the nextId(), I could check if the button was pressed (not figured out how to do that yet), and return Page 4 if the button was not pressed, but return Side_Page if the button was pressed.

                    Maybe there is a better way to achieve this?

                    Well using nextId sounds good. but the part of knowing if the button was clicked, will require a variable to keep track of that.

                    I've set a bool 'buttonPressed' to try and keep track.

                    You could also just define a new signal ( in that page class)
                    signals:
                    void GotoSidePage();

                    and connect that to a slot in myWizard, that actually set the page to this side page.

                    and for the (pushbutton on this page), you connect to a slot that does

                    emit GotoSidePage();

                    Then myWizard can just show that page.

                    I'd still be in the same dilemma though right? Because I'd still have to connect a signal from the page, to a slot in the wizard. Which is the same as trying to connect a button press signal on the page to the next() slot in the wizard?

                    Should I be setting the parent of each page here?

                    class firstPage: public QWizardPage
                    {
                        Q_OBJECT
                    
                    public:
                        firstPage(QWidget *parent = nullptr);
                    
                    

                    I tried firstPage(QWidget *parent = myWizard::myWizard); but I get error: qualified reference to 'myWizard' is a constructor name rather than a type in this context.

                    If it makes any difference, I've basically used the Qt wizard example https://doc.qt.io/qt-5/qtwidgets-dialogs-licensewizard-example.html as a basis. My setup is exactly the same.

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      AhmedAlshawi
                      wrote on last edited by
                      #10

                      @mrjj oh I just realised maybe I should clarify that I launch the wizard from my mainwindow.cpp. The user clicks a button which triggers a function that has this code:

                      myWizard wizard;
                      wizard.exec();
                      
                      mrjjM 1 Reply Last reply
                      0
                      • A AhmedAlshawi

                        @mrjj oh I just realised maybe I should clarify that I launch the wizard from my mainwindow.cpp. The user clicks a button which triggers a function that has this code:

                        myWizard wizard;
                        wizard.exec();
                        
                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #11

                        @AhmedAlshawi

                        • If it makes any difference, I've basically used the Qt wizard example

                        Hi
                        Yes that helped a lot :)

                        There is a much easier way to connect. Sorry about that. I forgot.
                        So no need to change parents or anything.

                        Inside the pages, you can use wizard()
                        to get access to the QWizard

                        So your button can be connected like

                        connect(button, SIGNAL(pressed()), wizard(), SLOT(next()));

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          AhmedAlshawi
                          wrote on last edited by
                          #12

                          @mrjj

                          connect(button, SIGNAL(pressed()), wizard(), SLOT(next()));

                          It worked!! So simple. Really appreciated thank you. I can access any of the wizard functions with just wizard()->

                          How did I miss that haha!

                          mrjjM 1 Reply Last reply
                          0
                          • A AhmedAlshawi

                            @mrjj

                            connect(button, SIGNAL(pressed()), wizard(), SLOT(next()));

                            It worked!! So simple. Really appreciated thank you. I can access any of the wizard functions with just wizard()->

                            How did I miss that haha!

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @AhmedAlshawi
                            Hurrray :)
                            Hehe yeah, Same though for myself too. I even fast check the doc. but Missed it.
                            First when you said what sample you used as a base, I saw it and went

                            🤦‍♀️

                            But on the bright side, i wont forget again :)

                            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