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. Same filed names in QWizard
Qt 6.11 is out! See what's new in the release blog

Same filed names in QWizard

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 751 Views 1 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.
  • M Offline
    M Offline
    Maluna34
    wrote on last edited by
    #1

    Hello,

    I have a QWizard with 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!!

    Pl45m4P 1 Reply Last reply
    0
    • M Maluna34

      Hello,

      I have a QWizard with 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!!

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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. B and C) will call A's constructor too

      BPage(QWidget *parent)
      : APage(parent)
      {
      registerField("second", secondField);
      }

      So it tries to register the page first a second time, when you actually want to register the second (B).


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      M 1 Reply Last reply
      3
      • Pl45m4P Pl45m4

        @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. B and C) will call A's constructor too

        BPage(QWidget *parent)
        : APage(parent)
        {
        registerField("second", secondField);
        }

        So it tries to register the page first a second time, when you actually want to register the second (B).

        M Offline
        M Offline
        Maluna34
        wrote on last edited by
        #3

        @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.

        JonBJ 1 Reply Last reply
        0
        • M Maluna34

          @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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Maluna34
          I don't see why you/one would use inheritance between your pages. Not doing so would avoid the issue.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved