View Full Version : QStackedWidget pass data between stacks and switch by pushbutton from the staks

14th November 2010, 12:25
Hello all,

I am very New to QT and C++. I usually do work in PHP and Perl.

I am trying to make a multi form app that will pass data between the forms.

FormStack: Has the QStackedWIdget
Form1: has a 2 buttons and textbox when either button is clicked the Next stack should show and have the button that was clicked and text from the 1`st forms textbox
Form2 has 2 buttons back and close and lable

The best solution i found for QT was to use QStackedWidget but i cant seem to find a way to make the staks communicate and pass the data between each other except with a button that is on the formstack(the form that holds the QstackedWidget

And for the life of me i cannot make the slots and signals work between forms or 2 windows. they seem to only work within the same form.

Please help me i spent 2 days trying to find a solution on the forms or in teh qt samples but no luck so far.

I have attached the sample code (a modified multiform i found on this form that is the base of my app)5456

Thank you very much for the help.

14th November 2010, 14:44
Looks like you got some coding to do. The signal/slot editor in the designer isn't as powerful as just coding C++, but it can help to get you started. However, what you seem to want is some wizard-type behavior. Doesn't QWizard match your requirements? It already has a lot of the functionality you need.

14th November 2010, 15:01
Franz, Thank you for your answer as i mentioned i have never programmed in C or QT i am learning this as i go, but most of what i found were info using the QSTackedwidget. I will give the Wizard a shot and see how things go. and i thank you for the help offer i appropriate it alot :-) Do you use skype or icq? maybe we can chat sometimes.

15th November 2010, 01:36
So i looked at QWizard and it does not serve my purpose i am posting the code with the slots that i made somehow i get no compile error but its not working please have a look. i am desperate :-( 5458

So i have now main window having the stackedWidget and that has 2 forms form1 form2
form 1 has 2 buttons pushButton1 and pushButton2 and a textbox form2 has a lable

what i am trying to do is when the form loads and i type in textbox then click on pushButton1or pushButton2 frm 2 should come to view in stackedwidget and lable on for 2 will have data from textbox of form1 plus an identifier for which button was clicked.

15th November 2010, 02:52
First off, you have the concept of stacked widgets wrong....if you search this forum you can get the answers to most of your questions...for example look at this thread http://www.qtcentre.org/threads/33130-Child-widgets?highlight=stacked. The widgets are placed on each page of the stacked widget, not separate forms for the stacked widget. I would strongly suggest getting a book on C++ and QT. But to help you out a bit, there are several ways to accomplish what you are looking for. In your main window, place the stacked widget, put the widgets that you want on each widget (change the "stack" by clicking on the arrow in the upper right corner of the stacked widget. Then you have to become familiar with signals and slots to navigate your forms or perform any action based on the users actions. In your case, one way is to right click on your button#1 and go to slots. Then click on the appropriate signal (clicked()). This will create the definition of your slot and you have to code in there what you want to do. All controls can be accessed by thier appropriate properties. I did a little down and dirty modification of your project as an example.
I hope this helps....I would get a book to help you understand and also search these forums...If you are a newbie, then your question probably has already been asked and answered.

19th November 2010, 16:02
Thank you for your help i was able to use the stackedWidget correctly with your explanation :-) I am reading a C++ book and a C++ QT book but sadly i dont have enough info from them yet. thus this is serving as a learning experience as well.

Thank you for all the help