I have a project in which I really would like to use the constructor for the visual design of my wizard.
When I first did this, I had a QWizard widget and each QWizardPage in separate .ui files, and then built a wizard by calling addPages (). It worked, but it was dirty because my project suddenly had one set of .h / .cpp / .ui files per page in the wizard.
Then I realized that a designer can add QWizardPage to QWizard itself and “promote” pages so that I can use my own class functionality. I only had one .ui file for QWizard and only two sets of .h / .cpp files (one for QWizard and one for each QWizardPage).
So my project looks something like this:
- Wizard.ui - contains all GUI elements for the wizard and related pages
- Wizard.h / .cpp - contains code for the QWizard derived class
- WizardPages.h / .cpp - contains code for each QWizardPage
It worked great! Until I started adding an implementation. The first thing I wanted to do was register the field on the first page (say, WizardPage1).
WizardPage1::WizardPage1(QWidget* parent) : QWizardPage(parent) { this->registerField("text*", textLineEdit); }
But 'textLineEdit' is actually a member of the QWizard object. So, I decided that I can register the field using the QWizardPage parent, however, the generated code in the ui_Wizard.h file creates QWizardPage objects without a parent. And when I try this:
Wizard::Wizard(QWidget *parent) : QWizard(parent) { setupUi(this);
But this crashes when I do:
Wizard* wizard = new Wizard(this); wizard->open();
Has anyone tried something like what I'm trying to accomplish and got it to work?
Addy source share