Results 1 to 15 of 15

Thread: using wizard

  1. #1
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default using wizard

    i am creating a wizard in which in first page, i ll be asking a number( say num in a textbox) from user and in next page i ll be creating as many textboxes as entered by user in previous page (that is in num)..
    initializePage() function of nextpage is:
    void NextPage::initializePage() //let NextPage be a class
    {
    no_of_textboxes=field("num").toInt(); //is not working however
    noOfTextboxes=field("num").toString();//is working
    }
    where no_of_textboxes(int type) and noOfTextboxes(QString type) are declared in class NextPage
    nd num is registered field of class PreviousPage.
    I tried
    no_of_textboxes=noOfTextboxes.toInt(); even this didn't work...
    Plz help ...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: using wizard

    "It doesn't work" is rarely an adequate description of a problem. What does it do? What were you expecting? What is the QVariant type and value of field("num")? What type of input widget is used to gather "num" on the first page?

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    Post complete, and compilabe example (see sig).

    Also use code tags.

    What is the (string) value of noOfTextboxes?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    ok if my post is ambigoius i am posting the original code ....

    Qt Code:
    1. class Dynamic : public QWizard
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit Dynamic(QWidget *parent = 0);
    6. ~Dynamic();
    7. void accept();
    8. };
    9. class GraphInfoPage: public QWizardPage
    10. {
    11. Q_OBJECT
    12. public:
    13. GraphInfoPage(QWidget *parent = 0);
    14.  
    15. private:
    16. QLabel *VerticesLabel;
    17. QLabel *EdgesLabel;
    18. QLineEdit *VerticesLineEdit;
    19. QLineEdit *EdgesLineEdit;
    20. };
    21. class VerticesInfoPage: public QWizardPage
    22. {
    23. Q_OBJECT
    24. public:
    25. VerticesInfoPage(QWidget *parent = 0);
    26. private:
    27. QLineEdit *LineEdit[];
    28. QLineEdit *LineEit;
    29. int v;
    30. QGridLayout *layout;
    31. protected:
    32. void initializePage();
    33.  
    34. };
    35. //dynamic.cpp
    36. Dynamic:: Dynamic(QWidget *parent) :
    37. QWizard (parent)
    38. {
    39. addPage(new GraphInfoPage);
    40. addPage(new VerticesInfoPage);
    41. setWindowTitle(tr("Graph Wizard"));
    42. }
    43. GraphInfoPage::GraphInfoPage(QWidget *parent): QWizardPage(parent)
    44. {
    45. setTitle(tr("<i>Enter Graph Details</i>"));
    46. VerticesLabel = new QLabel(tr("<b>Vertices:</b> "));
    47. QGridLayout *layout = new QGridLayout;
    48. VerticesLineEdit = new QLineEdit;
    49. VerticesLabel->setBuddy(VerticesLineEdit);
    50. VerticesLineEdit->setMaxLength(2);
    51. VerticesLineEdit->setMaximumWidth(35);
    52.  
    53. setLayout(layout);
    54. registerField("vertices*", VerticesLineEdit);
    55. layout->addWidget(VerticesLabel, 0,0);
    56. layout->addWidget(VerticesLineEdit,0,1);
    57. }
    58. VerticesInfoPage::VerticesInfoPage(QWidget *parent):QWizardPage(parent)
    59. {
    60. setTitle(tr("<i>Enter vertices: </i>"));
    61. layout = new QGridLayout;
    62. setLayout(layout);
    63. int k=0,j=0;
    64. LineEit=new QLineEdit;
    65. LineEit->setMaximumWidth(35);
    66. LineEit->setMaxLength(3);
    67. LineEit->setReadOnly(true);
    68.  
    69. layout->addWidget(LineEit,0,0);
    70. /* for(int i=1;i<v;i++)
    71.   {
    72.   LineEdit[i]=new QLineEdit;
    73.   LineEdit[i]->setMaximumWidth(35);
    74.   LineEdit[i]->setMaxLength(3);
    75.   layout->addWidget(LineEdit[i],++j,k);
    76.   if(j==4){j=0;k++;}
    77.   }*/
    78.  
    79. }
    80. void VerticesInfoPage::initializePage()
    81. {
    82. QString h=field("vertices").toString();
    83. LineEit->setText(h);
    84. }
    85. //main.cpp
    86.  
    87.  
    88.  
    89. #include <QtGui/QApplication>
    90. #include "dynamic.h"
    91.  
    92. int main(int argc, char *argv[])
    93. {
    94. QApplication a(argc, argv);
    95. Dynamic w;
    96. w.show();
    97.  
    98. return a.exec();
    99. }
    To copy to clipboard, switch view to plain text mode 
    if now I want to convert sting h to integer v...
    using
    bool *ok;
    v=h.toInt(ok,10);
    this is not working in the sense nothing is getting stored in v... to check i used following code
    char ch[2];
    ch[0]=v;
    ch[1]='\0';
    and displayed in textbox LineEit but nothing is displayed... I want 'v' to hold the integer value entered by user in first page so that I can create as many text boxes as user want in next page that is VerticesInfoPage.
    Hope I explained my problem ...plz help...

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: using wizard

    Oh dear, where to begin.
    Qt Code:
    1. bool *ok;
    2. v=h.toInt(ok,10);
    To copy to clipboard, switch view to plain text mode 
    The first line declares a pointer to a bool but does not allocate space for a bool or initialise the pointer so that the second line is using an uninitialised pointer. If the second line survives the real possibility of crashing then v will contain something: an integer has no "nothing" value. I suggest you take a good look at the example usage of QString::toInt()

    Your method of 'checking' is just plain broken. What do you expect to see if v == 0? What about v == 1? What is character 0 or 1?


    BTW: If you want the user to enter a number it would be wise to only allow the user to enter a number using either a QSpinBox or by putting a QIntValidator on the QLineEdit.

  6. #6
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    k.. i changed the above code and used spinbox instead..now can u plz tel me how to take the value of spinBox as integer in next page...?

  7. #7
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    first, have you seen thishttp://doc.qt.io/qt-4.8/QSpinBox?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  8. #8
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    yes i have already seen this class but there is only signal valueChanged ( int i ) where integer stores value of the spinbox but to which QObject should I connect this signal, i am not getting this...plz help

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    connect it to whatever object would like to know that information
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    but i want to store that in an integer .. is it possible??

  11. #11
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    it gives you the value in an integer. so what is the problem?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  12. #12
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    see since valueChanged ( int i ) is a signal i have to connect it to some slot but I want the value of (int) i to be stored in some variable int num...and int num is not a QObject, I can't connect to num.. then how can I take the value of integer i...

  13. #13
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    you want to store it in 'int num' - but where is 'int num'? It must be in some class, so attach the signal to that class

    Qt Code:
    1. class A : QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. void fire() {emit sig(5);}
    6.  
    7. signals:
    8. void sig(int);
    9. };
    10.  
    11. class B : QObject
    12. {
    13. Q_OBJECT
    14. public slots:
    15. void handleint(int i) {num = i;}
    16.  
    17. private:
    18. int num;
    19. };
    20.  
    21. // some testing
    22. void sometestclass:sometestfunc()
    23. {
    24. A a;
    25. B b;
    26.  
    27. QObject::connect(&a, SIGNAL(sig(int)), &b, SLOT(handleint(int));
    28.  
    29. a.fire(); // 5 is sent to b through the signal/slot
    30. }
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  14. #14
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: using wizard

    I did what u said but no value is getting stored in num... here i am giving the defination of my classes GraphInfoPage and VerticesInfoPage
    and num is private member of VerticesInfoPage...to check the value of num..i used spinBox in VertexInfoPage.. but no value of num is being displayed it is displaying 0..
    Qt Code:
    1. class GraphInfoPage: public QWizardPage
    2. {
    3. Q_OBJECT
    4. public:
    5. GraphInfoPage();
    6.  
    7. private:
    8.  
    9. int num;
    10. QLabel *VerticesLabel;
    11. QLabel *EdgesLabel;
    12. QSpinBox *edgesSpinbox;
    13. QSpinBox *verticesSpinbox;
    14. QGridLayout *layout;
    15.  
    16.  
    17. };
    18. class VerticesInfoPage: public QWizardPage
    19. {
    20. Q_OBJECT
    21. public:
    22. VerticesInfoPage(QWidget *parent = 0);
    23. private:
    24. QLineEdit *LineEdit[100];
    25. QLineEdit *LineEit;
    26. int num;
    27. const char *str;
    28. char ch[2];
    29. QGridLayout *layout;
    30. protected:
    31. void initializePage();
    32. public slots:
    33. void handleInt(int i){num=i;}
    34. };
    35. //dynamic.cpp
    36. GraphInfoPage::GraphInfoPage()
    37. {
    38. VerticesInfoPage vertex;
    39. setTitle(tr("<i><font color=blue>Enter Graph Details</font></i>"));
    40. VerticesLabel = new QLabel(tr("<b><font color=green>Vertices:</font></b> "));
    41. layout = new QGridLayout;
    42. EdgesLabel = new QLabel(tr("<b><font color=green>Edges:</font></b> "));
    43. verticesSpinbox=new QSpinBox();
    44. verticesSpinbox->setRange(0,100);
    45. connect(verticesSpinbox,SIGNAL(valueChanged(int)),&vertex,SLOT(handleInt(int)));
    46. edgesSpinbox=new QSpinBox();
    47. edgesSpinbox->setRange(0,100);
    48. registerField("vertices*",verticesSpinbox);
    49. registerField("edges*",edgesSpinbox);
    50. layout->addWidget(VerticesLabel,0,0);
    51. layout->addWidget(verticesSpinbox,0,1);
    52. layout->addWidget(EdgesLabel,2,0);
    53. layout->addWidget(edgesSpinbox,2,1);
    54. setLayout(layout);
    55. }
    56. VerticesInfoPage::VerticesInfoPage(QWidget *parent):QWizardPage(parent)
    57. {
    58. setTitle(tr("<i>Enter vertices: </i>"));
    59. layout = new QGridLayout;
    60. setLayout(layout);
    61. int k=0,j=0;
    62. LineEit=new QLineEdit;
    63. LineEit->setReadOnly(true);
    64. QSpinBox *Spinbox=new QSpinBox();
    65. Spinbox->setValue(num);
    66. layout->addWidget(Spinbox);
    67. //for creating text boxes
    68. for(int i=0;i<num;i++)
    69. {
    70. LineEdit[i]=new QLineEdit;
    71. LineEdit[i]->setMaximumWidth(35);
    72. LineEdit[i]->setMaxLength(3);
    73. layout->addWidget(LineEdit[i],++j,k);
    74. if(j==4){j=0;k++;}
    75. }
    76.  
    77. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by arjita; 28th July 2012 at 18:34.

  15. #15
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using wizard

    erm, in your code you just use local variable then connect to it. What do you think happens to local variable when it exits scope?

    Qt Code:
    1. GraphInfoPage::GraphInfoPage()
    2. {
    3. VerticesInfoPage vertex; <<<<<<<<<<<
    4. ...
    To copy to clipboard, switch view to plain text mode 

    that ^^ is pointless.

    It is also not the same page that you put in your wizard...

    Anyway, using wizard fields is much better http://doc.qt.io/qt-4.8/qwizard#registering-and-using-fields
    Last edited by amleto; 28th July 2012 at 18:53.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  16. The following user says thank you to amleto for this useful post:

    arjita (29th July 2012)

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2011, 11:14
  2. To Wizard or Not ?
    By fassage in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 10:42
  3. Using images in wizard
    By xfurrier in forum Newbie
    Replies: 1
    Last Post: 10th April 2009, 13:47
  4. Wizard and QTableWidget
    By rmagro in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2008, 18:00
  5. How to add a Wizard ?
    By npc in forum Qt Tools
    Replies: 4
    Last Post: 24th July 2007, 14:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.