PDA

View Full Version : Using registerField() from QWizardPage



Momergil
31st July 2013, 04:07
Hello!

I'm trying to write a QWizard with some QWizardPage s and I'm not being able to use the function registerField(...). The way I'm trying to implement this is as it's shown in the QtAssistant's QWizard page: I created some functions that return pointers to QWizardPage, and then add them with addPage() to an object created in my main() before my MainWindow.show().

To be more specific, the compiler rejects registerField(...) without object, and when I use the QWizardParge created inside those functions, it returns an error saying that registerField() is protected.



QWizardPage *createUserData()
{
QWizardPage *page = new QWizardPage;
page->setTitle("User data");

QLabel *label = new QLabel(QObject::tr("Please, fill the following spaces with your personal data."));
label->setWordWrap(true);

QLabel *spaceLabel = new QLabel("");

QLineEdit *LE_Username = new QLineEdit();
LE_Username->setPlaceholderText(QObject::tr("Fill your username here"));
LE_Username->setObjectName("LE_Username");

QLineEdit *LE_Undefined = new QLineEdit("");
LE_Undefined->setPlaceholderText(QObject::tr("<Nothing to be written here yet.>"));

registerField("LE_Username*",LE_Username); //Error: can't be used without object
page->registerField("LE_Username*",LE_Username); //Error: is protected

...


I'm glad for any help.


Momergil

ChrisW67
31st July 2013, 06:02
The compiler is correct. You are defining a free function, i.e. it is not part of a class, and as the compiler is telling you registerField() does not exist anywhere as a free function (line 18). Line 19 fails because it can only be called from a subclass of QWizardPage, i.e. protected.

The example in the QWizard docs clearly shows use of QWizardPage::registerField() in a QWizardPage subclass (and nowhere else)

Momergil
11th August 2013, 04:53
Hmmm, ok. Is there a way by witch I could use an equal or similar functionallity without having to create a subclass of QWizard/QWizardPage (i.e. create something similar to the mentioned example)?

ChrisW67
11th August 2013, 07:15
registerField() is protected: you must subclass to access it. I really do not see the drama in a simple subclass.

You can choose to implement some data sharing arrangement of your own any way you like.

Tataratata
12th August 2013, 08:17
Hi,

I have a similar question regarding registerField(). I have implemented a class ComponentsPage that inherits from QWizardPage (see code below).



ComponentsPage::ComponentsPage(QWidget *parent)
: QWizardPage(parent)
{

// Set Titles
// [...]

// Create Check Boxes
// [...]
customCheck = new QCheckBox(tr("Custom"));

// Create Line Edit
lineTest = new QLineEdit();

// Register Field
registerField("test", lineTest);

// Set Layout
// [...]
}

int ComponentsPage::nextId() const
{
if (customCheck->isChecked())
return NewWizard::Page_Custom;
else
return NewWizard::Page_Finish;

}


However if I register my QLineEdit using the registerField method and try to access it on the next page (another subclass of QWizardPage) an empty string is returned.



CustomPage::CustomPage(QWidget *parent)
: QWizardPage(parent)
{
// Set Titles
// [...]

// Access Field
QString hw = field("test").toString();

// Show String
testLabel = new QLabel (hw);

// Set Layout
// [...]

}


What did I get wrong? I would be grateful for any help!

Thanks,
Tara

Tataratata
1st September 2013, 16:19
I found my mistake. If you can read examples correctly... :)
So just in case somebody runs into the same problem: You cannot access your fields from the constructor of your page. Instead you need to reimplemend the initializePage() function and get your information there.

Thanks anyway,
Tara