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:

Qt Code:
  1. #ifndef CLASSWIZARD_H
  2. #define CLASSWIZARD_H
  3.  
  4. #include <QWizard>
  5.  
  6. QT_BEGIN_NAMESPACE
  7. class QCheckBox;
  8. class QGroupBox;
  9. class QLabel;
  10. class QSpinBox;
  11. class QLineEdit;
  12. class QVector<QLineEdit>;
  13. QT_END_NAMESPACE
  14.  
  15. //! [0]
  16. class ClassWizard : public QWizard
  17. {
  18. Q_OBJECT
  19.  
  20. public:
  21. ClassWizard(QWidget *parent = 0);
  22. };
  23.  
  24. class NumObjectsPage : public QWizardPage
  25. {
  26. Q_OBJECT
  27.  
  28. public:
  29. NumObjectsPage(QWidget *parent = 0);
  30.  
  31. private:
  32. QLabel *lblNumObjs;
  33. QSpinBox *leNumObjs;
  34. };
  35.  
  36. class ObjectsPage : public QWizardPage
  37. {
  38. Q_OBJECT
  39.  
  40. public:
  41. ObjectsPage(QWidget *parent = 0);
  42.  
  43. protected:
  44. void initializePage();
  45.  
  46. private:
  47. QVector<QSpinBox*> sbObjs;
  48. QVector<QLabel*> lblObjs;
  49. };
  50.  
  51. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include <QtGui>
  2. #include "classwizard.h"
  3.  
  4. ClassWizard::ClassWizard(QWidget *parent)
  5. : QWizard(parent)
  6. {
  7. addPage(new NumObjectsPage);
  8. addPage(new ObjectsPage);
  9.  
  10. setWindowTitle(tr("Wizard"));
  11. }
  12.  
  13.  
  14. NumObjectsPage::NumObjectsPage(QWidget *parent)
  15. : QWizardPage(parent)
  16. {
  17. lblNumObjs = new QLabel(tr("Number of Objects:"));
  18. leNumObjs = new QSpinBox();
  19. lblNumObjs->setBuddy(leNumObjs);
  20.  
  21. registerField("numObjs*", leNumObjs);
  22.  
  23. QGridLayout *layout = new QGridLayout;
  24. layout->addWidget(lblNumObjs, 0, 0);
  25. layout->addWidget(leNumObjs, 0, 1);
  26.  
  27. setLayout(layout);
  28. }
  29.  
  30. ObjectsPage::ObjectsPage(QWidget *parent)
  31. : QWizardPage(parent)
  32. {
  33. }
  34.  
  35. void ObjectsPage::initializePage()
  36. {
  37. QGridLayout *layout = new QGridLayout;
  38. QSpinBox* sbVel = NULL;
  39. QLabel* lblVel = NULL;
  40.  
  41. QString numLayers = field("numObjs").toString();
  42. int num = numLayers.toInt();
  43.  
  44. for (int i = 0; i < num; ++i) {
  45. sbVel = new QSpinBox();
  46. lblVel = new QLabel;
  47. lblVel->setText("Capa " + QString::number(i+1));
  48. sbObjs.push_back(sbVel);
  49. lblObjs.push_back(lblVel);
  50. layout->addWidget(lblVel, i, 0);
  51. layout->addWidget(sbVel, i, 1);
  52. }
  53.  
  54. setLayout(layout);
  55.  
  56. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include <QApplication>
  2. #include "classwizard.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication app(argc, argv);
  7. ClassWizard wizard;
  8. wizard.show();
  9. return app.exec();
  10. }
To copy to clipboard, switch view to plain text mode