PDA

View Full Version : Problem with QWizard (how to request a set of data on a QWizardPage k times??)



tobek123
3rd April 2009, 23:54
Hello

I am quite new to Qt so excuse me if my question is too noob for you. I have created an app which contains a QWizard (opened with File->New wizard). After several pages I get to a point where I have a page with 4 QLineEdit's (these are some parameters needed to select a bearing from a database). The problem is I would like to request those 4 parameters k times from the user and put them into arrays later (k was declared by the user a page before). Is it possible?? I am stuck. Please help, any clue would be hugely appreciated.

Toby

wysota
4th April 2009, 01:40
You either need to have several instances of the same page or instead of the lineedits use a table of some kind (QTableWidget probably).

tobek123
4th April 2009, 10:40
Thanx for your answer, I have tried QTableWidget, I am wondering how to validate fields in this table, so that I am sure that the user has filled them all. With QLineEdit there was no problem, I created a RegExp, a Validator and called setValidator() on them plus setting them as mandatory fields , so the "Next" button was greyed as long as there was an acceptable input. I've traversed the documentation for QTableWidget and QTableWidgetItem but I see no setValidator() function, even as inherited from other objects. Any thoughts ??

wysota
4th April 2009, 11:03
There is no automatic validation available for QTableWidget. What you can do is validate input inside the table widget using the item delegate but it is only a validation of a single field. It won't tell you if all the fields were filled in. You have to provide your own validating function that will iterate through all rows and fields and perform the checks.

tobek123
4th April 2009, 21:41
thank you, I will try it out then :)

tobek123
5th April 2009, 02:55
For anybody interested in a final solution, here it is. Using a QTableWidget with number of rows entered by the user a page before (mandatory field with an validator, so the value is 100% OK), 4 columns as I need 4 parameters, 2 important connections:

1. connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), this,
SLOT(validationSlot(QTableWidgetItem*))); - every change in any item triggers a validation function which simply uses a QRegExpValidator on a QTableWidgetItem::text() and if the outcome is QValidator::Invalid function sets the text of this item to ""

2. connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), this,
SIGNAL(completeChanged())); - needed for a correct reimplementation of isComplete() (triggered like above, everytime sb. changes a single cell) used for enabling/disabling the "Next" button, the isComplete() function body checks the bool outcome of an okToGo() function which checks if there are no empty items in the table (if there is anthing in there it must be good because of the validator)

Thank you for your help wysota, I appreciate it :)