Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Issue with Signals and Slots & QWizard



  • Hi,

    I have set up a QWizard in the same way as Qt licensewizard example. I launch the wizard from my mainWindow.cpp using wizard.exec;

    Within my wizard I want to pass information back over to my MainWindow. To do this I have done:


    mainwindow.cpp

    myWizard wizard;
    connect(&wizard, &myWizard::sendTheData, this, &MainWindow::recieveTheData);
    wizard.exec;
    

    The problem I am having is that I am not sure how emit the myWizard::sendTheData signal when the user presses Done to complete the wizard.

    I have tried to do this:

    void finalPage::setVisible(bool visible)
    {
       QWizardPage::setVisible(visible);
       connect(wizard()->button(QWizard::FinishButton), &QPushButton::clicked, wizard(), &myWizard::sendTheData );
    }
    

    but this gives me "no matching member function for call to 'connect'"


    I also tried, in mainWindow.cpp to connect a signal that is sent from the finalPage class to a slot in mainWindow, like below, but that also doesn't work.

    myWizard wizard;
    finalPage fp;
    connect(&fp, &finalPage::sendTheData, this, &MainWindow::recieveTheData);
    wizard.exec;
    

    Any help would be appreciated thank you!



  • @AhmedAlshawi

    Do you have the signals declared in your headers?

    You need something like

    signals:
       void sendTheData();
    

    in yourfinalPage.h


  • Lifetime Qt Champion

    Hi,

    You might be over-engineering it.

    You can simply give getters to your wizard and retrieve the data from it after calling exec. A wizard rarely needs signal and slots to pass data.



  • @Pl45m4

    Yeah definitely. Mywindow.h and mywizard.h both have the slot/signal.



  • @SGaist thanks for this direction.

    Could you share/link me to an example to show what you mean? I’ve not heard the term “getter” before 😅


  • Lifetime Qt Champion

    QWizard::currentPage is a getter for example.

    A getter is method that returns a value, pointer, etc. It might be implemented in tandem with a setter.

    Qt read/write properties have one of each for example.



  • @SGaist I was way over-engineering it!

    I just used registerField("fieldName", widget) for each of the fields in each of the QWizardPages that I wanted to take across to mainWindow. Then after wizard.exec in mainWindow, I just called QVariant item1 = wizard.field("fieldName"). Then I converted each of the QVariants to the types I wanted :)

    Works a charm. Thank you!!


Log in to reply