PDA

View Full Version : QWizard and mandatory field problems



Judd
5th August 2009, 06:12
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

numbat
5th August 2009, 11:52
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 (http://doc.trolltech.com/qq/qq22-qwizard.html#validatebeforeitstoolate).

Judd
5th August 2009, 12:50
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;
}