afflictedd2
19th March 2009, 01:32
Hi everyone,
I'm trying to build a wizard in which I specify a number of something, so that when I press next I should get that number of objects in the next screen. Problem is.. If I go back and change that number of objects and press next.. the number of objects will go unchanged. How do I tell QWizard to do this?
This is the simplified code, it runs:
#ifndef CLASSWIZARD_H
#define CLASSWIZARD_H
#include <QWizard>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QGroupBox;
class QLabel;
class QSpinBox;
class QLineEdit;
class QRadioButton;
class QVector<QLineEdit>;
QT_END_NAMESPACE
//! [0]
class ClassWizard : public QWizard
{
Q_OBJECT
public:
ClassWizard(QWidget *parent = 0);
};
class NumObjectsPage : public QWizardPage
{
Q_OBJECT
public:
NumObjectsPage(QWidget *parent = 0);
private:
QLabel *lblNumObjs;
QSpinBox *leNumObjs;
};
class ObjectsPage : public QWizardPage
{
Q_OBJECT
public:
ObjectsPage(QWidget *parent = 0);
protected:
void initializePage();
private:
QVector<QSpinBox*> sbObjs;
QVector<QLabel*> lblObjs;
};
#endif
#include <QtGui>
#include "classwizard.h"
ClassWizard::ClassWizard(QWidget *parent)
: QWizard(parent)
{
addPage(new NumObjectsPage);
addPage(new ObjectsPage);
setWindowTitle(tr("Wizard"));
}
NumObjectsPage::NumObjectsPage(QWidget *parent)
: QWizardPage(parent)
{
lblNumObjs = new QLabel(tr("Number of Objects:"));
leNumObjs = new QSpinBox();
lblNumObjs->setBuddy(leNumObjs);
registerField("numObjs*", leNumObjs);
QGridLayout *layout = new QGridLayout;
layout->addWidget(lblNumObjs, 0, 0);
layout->addWidget(leNumObjs, 0, 1);
setLayout(layout);
}
ObjectsPage::ObjectsPage(QWidget *parent)
: QWizardPage(parent)
{
}
void ObjectsPage::initializePage()
{
QGridLayout *layout = new QGridLayout;
QSpinBox* sbVel = NULL;
QLabel* lblVel = NULL;
QString numLayers = field("numObjs").toString();
int num = numLayers.toInt();
for (int i = 0; i < num; ++i) {
sbVel = new QSpinBox();
lblVel = new QLabel;
lblVel->setText("Capa " + QString::number(i+1));
sbObjs.push_back(sbVel);
lblObjs.push_back(lblVel);
layout->addWidget(lblVel, i, 0);
layout->addWidget(sbVel, i, 1);
}
setLayout(layout);
}
#include <QApplication>
#include "classwizard.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ClassWizard wizard;
wizard.show();
return app.exec();
}
I'm trying to build a wizard in which I specify a number of something, so that when I press next I should get that number of objects in the next screen. Problem is.. If I go back and change that number of objects and press next.. the number of objects will go unchanged. How do I tell QWizard to do this?
This is the simplified code, it runs:
#ifndef CLASSWIZARD_H
#define CLASSWIZARD_H
#include <QWizard>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QGroupBox;
class QLabel;
class QSpinBox;
class QLineEdit;
class QRadioButton;
class QVector<QLineEdit>;
QT_END_NAMESPACE
//! [0]
class ClassWizard : public QWizard
{
Q_OBJECT
public:
ClassWizard(QWidget *parent = 0);
};
class NumObjectsPage : public QWizardPage
{
Q_OBJECT
public:
NumObjectsPage(QWidget *parent = 0);
private:
QLabel *lblNumObjs;
QSpinBox *leNumObjs;
};
class ObjectsPage : public QWizardPage
{
Q_OBJECT
public:
ObjectsPage(QWidget *parent = 0);
protected:
void initializePage();
private:
QVector<QSpinBox*> sbObjs;
QVector<QLabel*> lblObjs;
};
#endif
#include <QtGui>
#include "classwizard.h"
ClassWizard::ClassWizard(QWidget *parent)
: QWizard(parent)
{
addPage(new NumObjectsPage);
addPage(new ObjectsPage);
setWindowTitle(tr("Wizard"));
}
NumObjectsPage::NumObjectsPage(QWidget *parent)
: QWizardPage(parent)
{
lblNumObjs = new QLabel(tr("Number of Objects:"));
leNumObjs = new QSpinBox();
lblNumObjs->setBuddy(leNumObjs);
registerField("numObjs*", leNumObjs);
QGridLayout *layout = new QGridLayout;
layout->addWidget(lblNumObjs, 0, 0);
layout->addWidget(leNumObjs, 0, 1);
setLayout(layout);
}
ObjectsPage::ObjectsPage(QWidget *parent)
: QWizardPage(parent)
{
}
void ObjectsPage::initializePage()
{
QGridLayout *layout = new QGridLayout;
QSpinBox* sbVel = NULL;
QLabel* lblVel = NULL;
QString numLayers = field("numObjs").toString();
int num = numLayers.toInt();
for (int i = 0; i < num; ++i) {
sbVel = new QSpinBox();
lblVel = new QLabel;
lblVel->setText("Capa " + QString::number(i+1));
sbObjs.push_back(sbVel);
lblObjs.push_back(lblVel);
layout->addWidget(lblVel, i, 0);
layout->addWidget(sbVel, i, 1);
}
setLayout(layout);
}
#include <QApplication>
#include "classwizard.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ClassWizard wizard;
wizard.show();
return app.exec();
}