Results 1 to 7 of 7

Thread: How can I registed field in QWizard, which designed in QtCreator?

  1. #1
    Join Date
    Sep 2009
    Location
    Russia
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How can I registed field in QWizard, which designed in QtCreator?

    I`m create QWizard and add several pages to it with QtCreator(built-in Qt Designer). I want to make some fields to be mandatory in constructor of QWizard, like this:
    Qt Code:
    1. this->page(0)->registerField("name*",m_ui->lname);
    To copy to clipboard, switch view to plain text mode 
    but this method of QWizardPage is protected. I can`t find constructor of QWizardPages, which has been added to .ui file in graphical mode

  2. #2
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can I registed field in QWizard, which designed in QtCreator?

    Hi,

    I see that this question is not answered and I have the exact same problem. In the QT Designer's created code, all of the widgets like QLineEdit are created in the setupUi function of the QWizard class and their parents are set to the related QWizardPage. I promoted all of the wizard pages in my wizard and if I try to use "registerField" in the constructor of my class inherited from the QWizardPage, I get "Segmentation fault" in run-time. I assume that's because registerField refers to QLineEdit widgets, which are not yet assigned to this wizard page, since they are created in the wizard's scope!

    However, if I try to use registerField in the Wizard's constructor, this time I cannot access the protected method of QWizardPage.

    I think, there must be a right way to do this and I am missing something. Otherwise, it would be pointless to use the QT Designer.


    The generated code:
    ui_Wizard.h
    Qt Code:
    1. ...
    2. class Ui_Wizard
    3. {
    4. public:
    5. PageSP *wizardPage_SP;
    6. QLineEdit *lineEdit_SP;
    7. QLabel *label_SP;
    8. QLabel *label_SPInfo;
    9. QFrame *frame_banner;
    10. QLabel *label_logo;
    11. QLabel *label_SP_W;
    12. QLabel *label_req_1;
    13.  
    14. ...
    15.  
    16. void setupUi (QWizard *Wizard)
    17. {
    18. ...
    19. wizardPage_SP = new PageSP();
    20. wizardPage_SP->setObjectName(QString::fromUtf8("wizardPage_SP"));
    21. wizardPage_SP->setFocusPolicy(Qt::TabFocus);
    22. lineEdit_SP = new QLineEdit(wizardPage_SP);
    23. lineEdit_SP->setObjectName(QString::fromUtf8("lineEdit_SP"));
    24. lineEdit_SP->setGeometry(QRect(180, 100, 183, 20));
    25. label_SP = new QLabel(wizardPage_SP);
    26. label_SP->setObjectName(QString::fromUtf8("label_SP"));
    27. label_SP->setGeometry(QRect(180, 80, 183, 16));
    28. ....
    29.  
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    Segmentation Fault Case
    My own class using the this Ui_Wizard class:
    configwizard.cpp
    Qt Code:
    1. ...
    2. PageSP::PageSP(QWidget *parent)
    3. : QWizardPage(parent)
    4. {
    5. registerField("f_SP*",this->findChild<QLineEdit *>("lineEdit_SP"),"plainText", SIGNAL(textChanged()));
    6. }
    To copy to clipboard, switch view to plain text mode 

    Protected method case
    configwizard.cpp
    Qt Code:
    1. ConfigWizard::ConfigWizard(QWizard *parent)
    2. {
    3. setupUi(this);
    4.  
    5. this->wizardPage_SP->registerField("f_SP*",this->lineEdit_SP);
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I registed field in QWizard, which designed in QtCreator?

    Have your page classes contain a public method "registerFields" (or name it whatever you want) which they use to register their fields (by calling registerField) and call that method for each page after the constructor of the wizard (or at least after its setupUi() call).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    markusthalberg (11th October 2011)

  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: How can I registed field in QWizard, which designed in QtCreator?

    I promoted all of the wizard pages in my wizard and if I try to use "registerField" in the constructor of my class inherited from the QWizardPage,
    This works just fine for me.
    I get "Segmentation fault" in run-time. I assume that's because registerField refers to QLineEdit widgets,
    Yes, the pointers you use must be valid when you use them. If you have used Designer to construct your QWizardPage then don't try register fields until after the generated setupUi() call in the constructor. You also don't need to use findChild(), just access the widget through the ui member/pointer. For example (from one of mine):
    Qt Code:
    1. RegoWizardPageIntro::RegoWizardPageIntro(QWidget *parent) :
    2. QWizardPage(parent),
    3. ui(new Ui::RegoWizardPageIntro)
    4. {
    5. ui->setupUi(this);
    6. setPixmap(QWizard::WatermarkPixmap, QPixmap(":/wizard/rego_watermark.png"));
    7. ...
    8.  
    9. // Register some of the radio buttons as fields
    10. registerField("action.activate", ui->registerRadioButton);
    11. registerField("action.deactivate", ui->unregisterRadioButton);
    12. ...
    13. }
    To copy to clipboard, switch view to plain text mode 
    which are not yet assigned to this wizard page, since they are created in the wizard's scope!
    Not sure what you mean by this? If you are creating widgets in the QWizard's constructor and injecting them into a QWizardPage's layout dynamically then you should reconsider your design.

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

    markusthalberg (11th October 2011)

  7. #5
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can I registed field in QWizard, which designed in QtCreator?

    Quote Originally Posted by ChrisW67 View Post
    Not sure what you mean by this? If you are creating widgets in the QWizard's constructor and injecting them into a QWizardPage's layout dynamically then you should reconsider your design.
    Actually, this is exactly my problem with the Designer's generated code. It creates the widgets of the WizardPage in Wizard's setupUi, after creating the WizardPage like in the "ui_Wizard.h" code above. If it were to me, I would have done it as you suggested. However, wysota's suggestion of defining a new public method in WizardPage worked for me.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I registed field in QWizard, which designed in QtCreator?

    But you are still injecting widgets that belong to some other widget into the pages.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    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: How can I registed field in QWizard, which designed in QtCreator?

    Actually, this is exactly my problem with the Designer's generated code. It creates the widgets of the WizardPage in Wizard's setupUi, after creating the WizardPage like in the "ui_Wizard.h" code above.
    If you use Designer to build the entire QWizard, including the pages then that is what you get. This approach keeps your source file count down but makes almost everything else awkward by hiding the widgets on the pages from easy access.

    If you use Designer to generate a set of wizard pages then the code to place the widgets on those pages is in the correct place and you can register fields in each page's constructor. Then create a QWizard, add your wizard pages (using Designer promotion) and all is well. That's how I did it in the example I posted.

    If you have inherited the awkward QWizard setup and cannot change it then what you have done will work.

Similar Threads

  1. QWizard and mandatory field problems
    By Judd in forum Qt Programming
    Replies: 2
    Last Post: 5th August 2009, 11:50
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48

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.