Call function from one form in another
-
Hello
I have a function that generates values in one form. Now i want to call that function on a second form to display on the second ui. Can anyone tell me if there is a method to do this?
-
Hello
I have a function that generates values in one form. Now i want to call that function on a second form to display on the second ui. Can anyone tell me if there is a method to do this?
@Shivam-Sharma said in Call function from one form in another:
Can anyone tell me if there is a method to do this?
The correct method in Qt are signals/slots: https://doc.qt.io/qt-5/signalsandslots.html
Connect signal from first form to a slot in second form. And emit the signal in first form if it generated something. -
Will try this and let you knwo.
-
@Shivam-Sharma said in Call function from one form in another:
Can anyone tell me if there is a method to do this?
The correct method in Qt are signals/slots: https://doc.qt.io/qt-5/signalsandslots.html
Connect signal from first form to a slot in second form. And emit the signal in first form if it generated something. -
Not being able to connect. Have tried how much I could, but not being able to figure it out. Could someone help, please.
-
Not being able to connect. Have tried how much I could, but not being able to figure it out. Could someone help, please.
@Shivam-Sharma
Show code attempt.At the end of the day won't it be:
connect(form1_instance, &form1_signal, form2_instance, &form2_slot);You will need to write that code in a module which includes both
form1.h&form2.h. That might potentially be eitherform1.cpporform2.cpp, or perhaps you have amainwindow.cppwhich includes bothform1.h&form2.h.