<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QWizard fields - enumeration or check for existance?]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">What I try to achieve:<br />
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.<br />
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:</p>
<p dir="auto">@// Data providing class<br />
class myData : public QObject {<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
Q_PROPERTY(QString name READ name WRITE setName)</p>
<p dir="auto">QString name() {return m_name;};<br />
void setName(const QString name) { m_name = name;};</p>
<p dir="auto">private:<br />
QString m_name;<br />
}</p>
<p dir="auto">// Somewhere in the GUI when setting up a Wizard Page:</p>
<p dir="auto">MyWizardPage::MyWizardPage(QWidget* parent) : QWizardPage(parent) {<br />
setupUi(this);<br />
// assume name is a LineEdit widget<br />
registerField("name", name, "currentText");<br />
}</p>
<p dir="auto">// in the Wizard class:</p>
<p dir="auto">void MyWizard::next() {<br />
// now I want to copy the data from the WizardPage back to the data class<br />
// (assume the var data is of type myData)</p>
<p dir="auto">// hard-wired method (strong dislike):<br />
<a href="http://data.name" target="_blank" rel="noopener noreferrer nofollow ugc">data.name</a> = field("name").toString();</p>
<p dir="auto">// instead I would prefer something like:<br />
for (int i = 0; i &lt; data.metaObject()-&gt;propertyCount(); i++) {<br />
QString propName = data.metaObject()-&gt;property(i).name();<br />
// at this point I'd like to check wether a field with the same name as the<br />
// property exists. Unfortunately I didn't find such a check.<br />
QString fieldVal = field(propName).toString;<br />
// the above call just returns "" when propName doesn't exist. That's not helpful,<br />
// because I can't find out wether the field exists and is empty, or doesn't exist.<br />
// The library obviously knows what's going on because it writes a message to the<br />
// debug log<br />
data.metaObject()-&gt;setProperty(propName, fieldVal);<br />
}<br />
QWizard::next();<br />
}@</p>
]]></description><link>https://forum.qt.io/topic/28347/qwizard-fields-enumeration-or-check-for-existance</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 19:54:29 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/28347.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Jun 2013 12:40:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QWizard fields - enumeration or check for existance? on Mon, 02 Sep 2013 19:26:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Did you try with QVariant::isNull() before doing the conversion you need ?</p>
]]></description><link>https://forum.qt.io/post/193824</link><guid isPermaLink="true">https://forum.qt.io/post/193824</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 02 Sep 2013 19:26:16 GMT</pubDate></item><item><title><![CDATA[Reply to QWizard fields - enumeration or check for existance? on Mon, 02 Sep 2013 08:03:44 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/193698</link><guid isPermaLink="true">https://forum.qt.io/post/193698</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 02 Sep 2013 08:03:44 GMT</pubDate></item></channel></rss>