Results 1 to 3 of 3

Thread: QWizard and mandatory field problems

  1. #1
    Join Date
    Jul 2009
    Location
    Launceston, Tasmania, Australia
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWizard and mandatory field problems

    Hello,

    I have a QWizard class with a number of QLineEdit's. I've registered the QLineEdits as such:

    registerField("companyName*", companynameLineEdit);
    registerField("firstname*", firstnameLineEdit);
    registerField("lastname*", lastnameLineEdit);

    The problem I have is, if I set all of these fields to mandatory, then all the fields have to be entered. However, in my program, any one of these fields needs to enable the 'Next' pushbutton. I've tried connecting the textChanged() signals of the QLineEdits, and connecting them to a slot which then iterates over the text of the QLineEdits: My function is:

    void ClassInfoPage::textChanged(const QString & text)
    {
    if(companyNameLineEdit->text()!="")
    registerField("companyName", companyNameLineEdit);
    else
    registerField("companyName*", companyNameLineEdit);
    if(firstnameLineEdit->text()!="")
    registerField("firstname", firstnameLineEdit);
    else
    registerField("firstname*", firstnameLineEdit);
    if(lastnameLineEdit->text()!="")
    registerField("lastname", lastnameLineEdit);
    else
    registerField("lastname*", lastnameLineEdit);
    }

    This, of course doesn't work. is there a way to de-register fields? Or is there a cleaner way to get the desired results? Any help would be appreciated. Thankyou

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWizard and mandatory field problems

    The documentation states:
    QWizard's mandatory field mechanism is provided for convenience. A more powerful (but also more cumbersome) alternative is to reimplement QWizardPage::isComplete() and to emit the QWizardPage::completeChanged() signal whenever the page becomes complete or incomplete.
    See here for a validation example.

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

    Judd (5th August 2009)

  4. #3
    Join Date
    Jul 2009
    Location
    Launceston, Tasmania, Australia
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: QWizard and mandatory field problems

    Thankyou
    That worked. The following code is what I used:

    connect(firstnameLineEdit, SIGNAL(selectionChanged()),
    this, SIGNAL(completeChanged()));
    connect(lastnameLineEdit, SIGNAL(selectionChanged()),
    this, SIGNAL(completeChanged()));
    connect(companyNameLineEdit, SIGNAL(selectionChanged()),
    this, SIGNAL(completeChanged()));

    bool ContactsPage::isComplete() const
    {
    if(field("firstname")!= "")
    return true;
    else if(field("lastname")!= "")
    return true;
    else if(field("companyName")!= "")
    return true;
    else
    return false;
    }

Similar Threads

  1. QWizard - mandatory fields
    By slava in forum Qt Programming
    Replies: 12
    Last Post: 12th February 2008, 13:52

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.