Results 1 to 6 of 6

Thread: Using registerField() from QWizardPage

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Using registerField() from QWizardPage

    Hello!

    I'm trying to write a QWizard with some QWizardPage s and I'm not being able to use the function registerField(...). The way I'm trying to implement this is as it's shown in the QtAssistant's QWizard page: I created some functions that return pointers to QWizardPage, and then add them with addPage() to an object created in my main() before my MainWindow.show().

    To be more specific, the compiler rejects registerField(...) without object, and when I use the QWizardParge created inside those functions, it returns an error saying that registerField() is protected.

    Qt Code:
    1. QWizardPage *createUserData()
    2. {
    3. QWizardPage *page = new QWizardPage;
    4. page->setTitle("User data");
    5.  
    6. QLabel *label = new QLabel(QObject::tr("Please, fill the following spaces with your personal data."));
    7. label->setWordWrap(true);
    8.  
    9. QLabel *spaceLabel = new QLabel("");
    10.  
    11. QLineEdit *LE_Username = new QLineEdit();
    12. LE_Username->setPlaceholderText(QObject::tr("Fill your username here"));
    13. LE_Username->setObjectName("LE_Username");
    14.  
    15. QLineEdit *LE_Undefined = new QLineEdit("");
    16. LE_Undefined->setPlaceholderText(QObject::tr("<Nothing to be written here yet.>"));
    17.  
    18. registerField("LE_Username*",LE_Username); //Error: can't be used without object
    19. page->registerField("LE_Username*",LE_Username); //Error: is protected
    20.  
    21. ...
    To copy to clipboard, switch view to plain text mode 

    I'm glad for any help.


    Momergil

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using registerField() from QWizardPage

    The compiler is correct. You are defining a free function, i.e. it is not part of a class, and as the compiler is telling you registerField() does not exist anywhere as a free function (line 18). Line 19 fails because it can only be called from a subclass of QWizardPage, i.e. protected.

    The example in the QWizard docs clearly shows use of QWizardPage::registerField() in a QWizardPage subclass (and nowhere else)

  3. The following user says thank you to ChrisW67 for this useful post:

    Momergil (11th August 2013)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using registerField() from QWizardPage

    Hmmm, ok. Is there a way by witch I could use an equal or similar functionallity without having to create a subclass of QWizard/QWizardPage (i.e. create something similar to the mentioned example)?

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using registerField() from QWizardPage

    registerField() is protected: you must subclass to access it. I really do not see the drama in a simple subclass.

    You can choose to implement some data sharing arrangement of your own any way you like.

  6. #5

    Default Re: Using registerField() from QWizardPage

    Hi,

    I have a similar question regarding registerField(). I have implemented a class ComponentsPage that inherits from QWizardPage (see code below).

    Qt Code:
    1. ComponentsPage::ComponentsPage(QWidget *parent)
    2. : QWizardPage(parent)
    3. {
    4.  
    5. // Set Titles
    6. // [...]
    7.  
    8. // Create Check Boxes
    9. // [...]
    10. customCheck = new QCheckBox(tr("Custom"));
    11.  
    12. // Create Line Edit
    13. lineTest = new QLineEdit();
    14.  
    15. // Register Field
    16. registerField("test", lineTest);
    17.  
    18. // Set Layout
    19. // [...]
    20. }
    21.  
    22. int ComponentsPage::nextId() const
    23. {
    24. if (customCheck->isChecked())
    25. return NewWizard::Page_Custom;
    26. else
    27. return NewWizard::Page_Finish;
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 
    However if I register my QLineEdit using the registerField method and try to access it on the next page (another subclass of QWizardPage) an empty string is returned.

    Qt Code:
    1. CustomPage::CustomPage(QWidget *parent)
    2. : QWizardPage(parent)
    3. {
    4. // Set Titles
    5. // [...]
    6.  
    7. // Access Field
    8. QString hw = field("test").toString();
    9.  
    10. // Show String
    11. testLabel = new QLabel (hw);
    12.  
    13. // Set Layout
    14. // [...]
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    What did I get wrong? I would be grateful for any help!

    Thanks,
    Tara

  7. #6

    Default Re: Using registerField() from QWizardPage

    I found my mistake. If you can read examples correctly...
    So just in case somebody runs into the same problem: You cannot access your fields from the constructor of your page. Instead you need to reimplemend the initializePage() function and get your information there.

    Thanks anyway,
    Tara

Similar Threads

  1. Replies: 1
    Last Post: 8th August 2013, 14:57
  2. Replies: 0
    Last Post: 31st March 2013, 21:17
  3. QWizard and using registerField on a QRadioButton
    By cprokopiak in forum Qt Programming
    Replies: 1
    Last Post: 31st December 2011, 07:46
  4. Custom registerfield
    By parsnips146 in forum Newbie
    Replies: 0
    Last Post: 25th August 2010, 15:30
  5. QWizard, QComboBox and registerField() issue
    By RThaden in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 12:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.