Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWizard fields - enumeration or check for existance?
Forum Updated to NodeBB v4.3 + New Features

QWizard fields - enumeration or check for existance?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Batox
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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();
    }@

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Batox
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Did you try with QVariant::isNull() before doing the conversion you need ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved