I have a program - the main window, how do I launch the QWizardPage by pressing a button from the main window menu. Creating an instance of the class and using the show method produces a short-term start. Even in the logs there is nothing.
2 answers
Create the NewProjectMainPage class inherited from QWizardPage (for example) by adding the functionality of the QWizardPage class:
code of the file NewProjectMainPage.h
#ifndef NEWPROJECTMAINPAGE_H #define NEWPROJECTMAINPAGE_H #include <QWizardPage> namespace Ui { class NewProjectMainPage; } class NewProjectMainPage : public QWizardPage { Q_OBJECT public: explicit NewProjectMainPage(QWidget *parent = 0); ~NewProjectMainPage(); void initializePage() override; bool validatePage() override; private: Ui::NewProjectMainPage *ui; }; #endif // NEWPROJECTMAINPAGE_H code of the file NewProjectMainPage.cpp
#include "NewProjectMainPage.h" #include "ui_NewProjectMainPage.h" #include <QDir> NewProjectMainPage::NewProjectMainPage(QWidget *parent) : QWizardPage(parent), ui(new Ui::NewProjectMainPage) { ui->setupUi(this); } NewProjectMainPage::~NewProjectMainPage() { delete ui; } void NewProjectMainPage::initializePage() { registerField("projectName*", ui->projectNameEdit); registerField("projectLocation*", ui->projectLocationEdit); setField("projectName", "Untitled"); setField("projectLocation", QDir::homePath()); } bool NewProjectMainPage::validatePage() { if (field("projectName").toString().contains('?')) { return false; } return true; } Now the class can be used as a normal page for QWizard:
NewProjectWizard *wizard = new NewProjectWizard(parentWidget); wizard->setOption(QWizard::IndependentPages); wizard->setOption(QWizard::NoBackButtonOnStartPage); wizard->addPage(new NewProjectMainPage(wizard)); ... Now actually how to show the page as a separate window, not a page.
In the slot of the main window at the press of a button:
NewProjectMainPage *page = new NewProjectMainPage(this); page->setWindowFlags(Qt::Window); page->show(); Option:
NewProjectMainPage *page = new NewProjectMainPage(); page->show(); In the first case, you make the window a child of the main window, for its normal display it was necessary to set the Qt::Window flag
In the second case, we create a page window without a parent, in which case the default flag works fine: Qt::Widget
(don't forget to remove the dynamically allocated memory under the page)
If you have more questions, please ask in the comments.
- Please add an answer using
QWizardPagewithQWizard, since otherwise the first one becomes a regular widget without carrying the payload from its own specialization. - alexis031182 - @ alexis031182 ok added - asianirish
In the end, did so in the .h file
QWizard createwizard; in the .cpp file
createwizard.setWindowModality(Qt::ApplicationModal); createwizard.setPage(CREATE_PAGE, new WizardCreate); createwizard.setPage(DISTANCE_PAGE, new WizardDistance); createwizard.setPage(GROUP_PAGE, new WizardGroup); createwizard.setPage(PERSON_PAGE, new WizardPerson); createwizard.show(); where CREATE_PAGE,... is an enumeration
QWizardPagewithoutQWizarddoes not make sense. What is a "short run"? Give a minimal example of code that demonstrates your attempt to use the wizard. - alexis031182