QWizard fields - enumeration or check for existance?
-
I would like to check in a QWizard wether a field with a certain name exists. Alternatively I'd be happy if I could enumerate all currently registered fields in the Wizard. I'm not aware of either function.
What I try to achieve:
I have a class which provides data for a QWizard. Nearly all of the wizard-relevant fields of that data class are properties, accessible through Qt's meta object system.
Now I'd like to automatically "mate" the data fields with the wizards widgets, without the need to hard-code each such connection by hand. Example:@// Data providing class
class myData : public QObject {
Q_OBJECTpublic:
Q_PROPERTY(QString name READ name WRITE setName)QString name() {return m_name;};
void setName(const QString name) { m_name = name;};private:
QString m_name;
}// Somewhere in the GUI when setting up a Wizard Page:
MyWizardPage::MyWizardPage(QWidget* parent) : QWizardPage(parent) {
setupUi(this);
// assume name is a LineEdit widget
registerField("name", name, "currentText");
}// in the Wizard class:
void MyWizard::next() {
// now I want to copy the data from the WizardPage back to the data class
// (assume the var data is of type myData)// hard-wired method (strong dislike):
data.name = field("name").toString();// instead I would prefer something like:
for (int i = 0; i < data.metaObject()->propertyCount(); i++) {
QString propName = data.metaObject()->property(i).name();
// at this point I'd like to check wether a field with the same name as the
// property exists. Unfortunately I didn't find such a check.
QString fieldVal = field(propName).toString;
// the above call just returns "" when propName doesn't exist. That's not helpful,
// because I can't find out wether the field exists and is empty, or doesn't exist.
// The library obviously knows what's going on because it writes a message to the
// debug log
data.metaObject()->setProperty(propName, fieldVal);
}
QWizard::next();
}@ -
There really doesn't seem to be a built-in method to solve this problem. I wrote a wrapper function for regeisterField() which adds the field name to a QStringList. Then I can check that list for existance of a field name.
-
Hi,
Did you try with QVariant::isNull() before doing the conversion you need ?