How to use field of the qwizard?
-
what I want is:
create a wizard, when I click "finish", I can get some data of the wizardpages.for example, a wizard with 2 pages:
1 page contains a ListWidget
2 page is just for finishing this wizard.what i want is: when I click "finish", I can get a list which contains all of the items in that ListWidget.
for this goal, I do like this:
I create a WizardPage2 who inherits the class QWizardPage.
in the ui of this class, there is a QListWidget.
i code like this in his constructor:
@
registerField("liste", ui->listWidget);
@and I create a AideWizard who inherits the class QWizard, and I overwrite his fonction: accept()
@
void AideWizard::accept()
{
//I dont know how to recover that QListWidget with field("name");
QWizard::accept();
}
@I ve tried to find some examples but all of them are about recovering some QString. but for me, I want to recover a QListWidget.
can u help me???
-
Hi,
You should think more abstract and think about who needs the data, not who will supply it. Somebody will start the Wizard, so that piece of code will own the wizard class construction. When the wizard returns 'accepted' like any other dialog the class is still there. Use a 'getter' function in your wizard class to supply the creator to receive the data. The data may be anything that can be hold in a QVariant ;-)
So more like this:
@
// This is the class that creates the wizard dialog
MyWizard * AskStuff_p = new MyWizard(this);
if (AskStuff_p.exec() == QDialog::accept)
{
QList MyList = AskStuff_p.GetList();
}// And in your Wizard dialog somewhere:
QList MyWizard::GetList(void)
{
QList NewList;
NewList.append(ui->listItem); // Fill the list from GUI elementsreturn NewList;
}
@
Could check some code in an old project, but this should do it. -
Alternative:
You could subclass QListWidget for use in your wizard. Provide the subclass with a Q_PROPERTY that returns whatever you want from the list as a QStringList (or some other type that can go in a QVariant) and provide a changed signal. Then register a field:
@
registerField("liste", ui->subclassedListWidget, "myDataProperty", "myDataPropertyChanged");
@After the dialog is accepted the value can be retrieved using QWizard::field()
-
ah, this is exactly what i need.
thx a lot
[quote author="Jeroentje@home" date="1391021915"]Hi,
You should think more abstract and think about who needs the data, not who will supply it. Somebody will start the Wizard, so that piece of code will own the wizard class construction. When the wizard returns 'accepted' like any other dialog the class is still there. Use a 'getter' function in your wizard class to supply the creator to receive the data. The data may be anything that can be hold in a QVariant ;-)
So more like this:
@
// This is the class that creates the wizard dialog
MyWizard * AskStuff_p = new MyWizard(this);
if (AskStuff_p.exec() == QDialog::accept)
{
QList MyList = AskStuff_p.GetList();
}// And in your Wizard dialog somewhere:
QList MyWizard::GetList(void)
{
QList NewList;
NewList.append(ui->listItem); // Fill the list from GUI elementsreturn NewList;
}
@
Could check some code in an old project, but this should do it.[/quote]