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.