Same filed names in QWizard
-
Hello,
I have a
QWizardwith the first page containing a combo box which will determine the next page.
And the three next pages inherit from each other (A <- B <- C) because B just adds a new field to the APage, and C adds a new field to the BPage.Wizard(QWidget *parent) : QWizard(parent) { setPage(0, new TypePage); setPage(1, new APage); setPage(2, new BPage); // BPage inherits from APage setPage(3, new CPage); // CPage inherits from BPage } TypePage(QWidget *parent) : QWizardPage(parent) { registerField("type", type); } int nextId() const { const auto type = field("type").value<Type>(); switch (type) { case Type::A: return 1; case Type::B: return 2; case Type::C: return 3; default: return -1; } } APage(QWidget *parent) : QWizardPage(parent) { registerField("first", firstField); } int APage::nextId() const { return -1; } BPage(QWidget *parent) : APage(parent) { registerField("second", secondField); } CPage(QWidget *parent) : BPage(parent) { registerField("third", thirdField); }But I have the following error:
QWizardPage::addField: Duplicate field 'first'As we will never have A or B or C at the same time, it's not possible to use the same field name?
Do I have to create the pages dynamically, or there is no other solution than override field names in the subclasses?Thanks for your help!!
-
Hello,
I have a
QWizardwith the first page containing a combo box which will determine the next page.
And the three next pages inherit from each other (A <- B <- C) because B just adds a new field to the APage, and C adds a new field to the BPage.Wizard(QWidget *parent) : QWizard(parent) { setPage(0, new TypePage); setPage(1, new APage); setPage(2, new BPage); // BPage inherits from APage setPage(3, new CPage); // CPage inherits from BPage } TypePage(QWidget *parent) : QWizardPage(parent) { registerField("type", type); } int nextId() const { const auto type = field("type").value<Type>(); switch (type) { case Type::A: return 1; case Type::B: return 2; case Type::C: return 3; default: return -1; } } APage(QWidget *parent) : QWizardPage(parent) { registerField("first", firstField); } int APage::nextId() const { return -1; } BPage(QWidget *parent) : APage(parent) { registerField("second", secondField); } CPage(QWidget *parent) : BPage(parent) { registerField("third", thirdField); }But I have the following error:
QWizardPage::addField: Duplicate field 'first'As we will never have A or B or C at the same time, it's not possible to use the same field name?
Do I have to create the pages dynamically, or there is no other solution than override field names in the subclasses?Thanks for your help!!
@Maluna34 said in Same filed names in QWizard:
But I have the following error:
QWizardPage::addField: Duplicate field 'first'
As we will never have A or B or C at the same time, it's not possible to use the same field name?Because in A's constructor you call
registerField("first")and every derived class from A (i.e.BandC) will call A's constructor tooBPage(QWidget *parent)
: APage(parent)
{
registerField("second", secondField);
}So it tries to register the page
firsta second time, when you actually want to register thesecond(B). -
@Maluna34 said in Same filed names in QWizard:
But I have the following error:
QWizardPage::addField: Duplicate field 'first'
As we will never have A or B or C at the same time, it's not possible to use the same field name?Because in A's constructor you call
registerField("first")and every derived class from A (i.e.BandC) will call A's constructor tooBPage(QWidget *parent)
: APage(parent)
{
registerField("second", secondField);
}So it tries to register the page
firsta second time, when you actually want to register thesecond(B). -
@Pl45m4
Thanks for your help!Yes I know why I have this error.
But in this case how can I fix it, knowing that I'm using inheritance between my pages.