Results 1 to 15 of 15

Thread: How to pass information between wizardpages without widgets

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to pass information between wizardpages without widgets

    Hi!

    I am making a GUI app with wizard structure and I have:

    • the main.cpp
    • the class MainWindow : public QMainWindow basic class
    • class BaseWizard : public QWizard
    • class BasePage : public QWizardPage
    • all the pages(wp1, wp2, wp3 …) like this: class WP1 : public BasePage (they inherit from BasePage)


    Then in wp1 I have 2 big buttons which you can focus the with tab. If you press 'L' when button1 has focus, you go to wp2, and if the focus is on button2, you go to wp3.

    Now I want to know if the user choose to go to wp2 or wp3, so I decided to put a var (int iA; ) in Basepage (cause its common to all pages) and change iA's value on the page I want to, so I have:

    On basepage.h:
    Qt Code:
    1. public:
    2. void setA(int i);
    3. int getA() {return iA;};
    4. private:
    5. int iA;
    To copy to clipboard, switch view to plain text mode 

    on wp2.cpp:

    Qt Code:
    1. void WP2::initializePage()
    2. {
    3. BasePage::setA(0);
    4. }
    To copy to clipboard, switch view to plain text mode 

    on wp3.cpp:

    Qt Code:
    1. void WP3::initializePage()
    2. {
    3. BasePage::setA(1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    So I know that if getiA() returns 0 means the user chose the first option, and if it returns 1 the user chose the second.

    The problem is that setA() works fine but then the var iA gets any number lately, and I don't make any other setA()... so when I am on w5 and I want to do a BasePage::getA() it returns 0 or 4 or 5 or... instead of (in case the user chose the second button) ...1 .

    Any idea of why? Any idea of how can I pass the information throw wizardpages?

    I know that you can registerfield() but that is only for wdgets like lineedits, so it doesn't work here.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to pass information between wizardpages without widgets

    Quote Originally Posted by roseicollis View Post
    Any idea of why?
    Why would changing one object's iA variable change the value of another object's iA variable?
    In C++ an instance of a class is independent of any other instance of that class.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to pass information between wizardpages without widgets

    Then how can I pass the information throw wizardpages?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to pass information between wizardpages without widgets

    How about dynamic properties on BaseWizard ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass information between wizardpages without widgets

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to pass information between wizardpages without widgets

    Quote Originally Posted by roseicollis View Post
    Then how can I pass the information throw wizardpages?
    Well, since we are talking about C++:
    - through an object that all pages have access to
    - through using static members in the base class

    Cheers,
    _

  7. #7
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to pass information between wizardpages without widgets

    Ty wysota, as I said I already saw the registerField but what I didn't see are the fileds property and changedsignal,

    Qt Code:
    1. void QWizardPage::registerField ( const QString & name, QWidget * widget, const char * property = 0, const char * changedSignal = 0 )
    To copy to clipboard, switch view to plain text mode 

    So I suppose that I have to do something like this to get the focus change:
    registerField("First_Option", button1, focus , somesignalhere);
    But I can’t see how does it works with or without the ‘supposed’ signal.

    ----------

    anda_skoa:
    - through an object that all pages have access to
    - through using static members in the base class
    That's why I created int iA in basepage, trying to have a var which is common to all, but I suppose that this is not the way??

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass information between wizardpages without widgets

    Quote Originally Posted by roseicollis View Post
    But I can’t see how does it works with or without the ‘supposed’ signal.
    No idea what you mean. I have no idea why you'd want to set a field which keeps information whether a particular widget has focus or not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to pass information between wizardpages without widgets

    No idea what you mean. I have no idea why you'd want to set a field which keeps information whether a particular widget has focus or not.
    I have the first wizard page: WP1
    - with the fist button u go to WP2
    - with the second button u go to WP3

    this are 2 diferent ways of pages but both go to WPEnd.
    Then in WPEnd I need to know if user arrived there throw WP2 way or throw WP3 way and that is what I am trying to do: a way to know that.

  10. #10
    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: How to pass information between wizardpages without widgets

    Each QWizardPage is a QWidget.
    Give the page that has the buttons:
    • a getter and setter for the value you want to pass,
    • a declaration of the property
    • a signal to indicate it has changed (you may not even need this)

    And then register the page widget and property as the field.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass information between wizardpages without widgets

    Quote Originally Posted by roseicollis View Post
    I have the first wizard page: WP1
    - with the fist button u go to WP2
    - with the second button u go to WP3

    this are 2 diferent ways of pages but both go to WPEnd.
    Then in WPEnd I need to know if user arrived there throw WP2 way or throw WP3 way and that is what I am trying to do: a way to know that.
    Hmm... usually in a wizard you would have some widget (a checkbox, command button or radio button) for choosing the variant and then you would click the "Next" button to go to the next page according to that variant. What you want to do is very unusual for a wizard (the user would expect to traverse pages via Next and Previous buttons).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to pass information between wizardpages without widgets

    I've never needed to write a wizard but, IMO, it's only a matter of data organization.
    (1) All "shared" data (shared between wizard pages) need to be data items of the BaseWizard instance. For example, the iA variable belongs to the BaseWizard, not to the BasePage.
    (2) The QWizardPage class has a (protected) QWizardPage::wizard() method for accessing the wizard which the page belongs to.
    (3) Using the pointer, all pages have access to the "shared" data. They can store any status there and the final page can check what it wants.
    Last edited by Radek; 24th January 2015 at 05:16.

  13. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to pass information between wizardpages without widgets

    Quote Originally Posted by roseicollis View Post
    anda_skoa:

    That's why I created int iA in basepage, trying to have a var which is common to all, but I suppose that this is not the way??
    The variable is common to all pages, each page has it.
    But each page is an independent object, so each page has its own value.

    Just consider physical objects if in doubt: e.g. changing the content of my fridge does not change the content of your fridge, despite both having the same base class "cooled food storage kitchen appliance".

    Cheers,
    _

  14. The following user says thank you to anda_skoa for this useful post:

    roseicollis (2nd February 2015)

  15. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to pass information between wizardpages without widgets

    That's why I created int iA in basepage, trying to have a var which is common to all, but I suppose that this is not the way??
    You are confused about base classes, derived classes, and instances of them. A base class is simply a place to put all of the variables and methods that each derived class inherits. Inheriting is not sharing. If you define a member variable called "iA" in a base class, that means that every derived class will have a variable called "iA" that it inherits from the base class. When you instantiate a derived class (i.e. call "new MyDerivedClass()"), C++ creates a new instance of the class with its own value for iA. Changing the value of iA in one instance has no effect at all on the value of iA in other instances of the class.

    The only way to achieve what you want through a member variable is to make that member static. A static member variable's value is shared among all instances of a class, so changing iA's value in one instance changes the value seen by all other instances. If the static member is in the base class, then all derived classes inherit the variable and all instances of all derived classes share the same value.

    But as others have said, the QWizard architecture already has features built in to enable you to determine how you have arrived at a certain wizard page, and how to change where you go next depending on what happens in the current page. You don't need to reinvent that wheel.

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

    roseicollis (2nd February 2015)

  17. #15
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to pass information between wizardpages without widgets

    Hi, thanks to all for your help. Its solved now.

    Thank you so much d_stranz. You were totally right and I was mixing some terms. Now I have it clear so I could fix the problem.

Similar Threads

  1. Replies: 14
    Last Post: 27th November 2011, 14:13
  2. pass mouse event information to another widget
    By Rooster in forum Qt Programming
    Replies: 5
    Last Post: 12th July 2008, 04:23
  3. No information on the console
    By starcontrol in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2008, 13:39
  4. QT app information
    By CHeader in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2008, 11:07
  5. Getting MAC Information from qt?
    By vishal.chauhan in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2007, 09:31

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.