Re: Multiple Forms Handling
Try like this...
create a pointer to form2 in form1 class. allocate memory in constructor.
inside button_on_click slot
call pointer->show();
Re: Multiple Forms Handling
It works. I also found out the I did a mistake. there is no on clicked events.
Anway I am one more doubt on multiple forms. How can I pass variables of one forms to another.
ie form 1->label 1->text (lbl1) to form 2's->QString str
Re: Multiple Forms Handling
I have the same problem.
Have you found the way to access to form1 variables from form2?
Re: Multiple Forms Handling
To pass a variable you should create a public pointer of the same tipe as the widget from the form you want to get the data from, and, in the constructor of the class you initialize them to the ui element.
Re: Multiple Forms Handling
Quote:
When I tried to new form1 like the below code
Form2 *f2 = new Form2(this) <- under button click on form 1
f2.show();
I got error
error: request for member ‘show’ in ‘a’, which is of non-class type ‘form1*’
The error message tells you exactly what is wrong here (or at least it would if it matched the code snippet). "a" is "f2" and "form1*" is "Form2 *" in your code snippet. "f2" is a pointer to an object. "f2.show()" tries to to treat f2 as an instance of the class Form2.
To your original question regarding sharing something between two forms you have several obvious options:- Pass the value into the constructor of Form2
- Create a member variable inside Form2 and a public setter function. Call the setter after creating an instance of Form2.
- If the value can change in Form1 while Form2 is open, and the change should be reflected in Form2, then use a signal in Form1 and slot in Form2.
- Rethink your design if items inside Form1 do not logically belong there.