[Solved] 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:
@public:
void setA(int i);
int getA() {return iA;};
private:
int iA;@on wp2.cpp:
@void WP2::initializePage()
{
BasePage::setA(0);
}@on wp3.cpp:
@void WP3::initializePage()
{
BasePage::setA(1);
}@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.
-
Hi,
registerField can be used for other widgets. Take a look again at the signature, you can give it a property name and changedSignal, so it means that you can use it with custom widget having their own properties
-
Hi,
Mmmm I have see what you say:
@void QWizardPage::registerField ( const QString & name, QWidget * widget, const char * property = 0, const char * changedSignal = 0 )@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.
-
when you call field("First_Option") it will get the value of the focus property of button1
-
A trick you can also employ with registerFields is to realize that it works with a property on any widget, and that QWizardPage is a widget too... So, if you don't want to or just can't use a widget on the page, you can also use the page itself. Just define your own Q_PROPERTY on it to represent the value you want to share, and register that property.
-
Solved! Thank you so much.