Unsolved variable transfer between two forms
-
Hello. I want to send the data in a variable from the first form to the second form. I studied many topics in the forum, but did not understand anything. Can you please help?
-
@fkaraokur You can use signals/slots for that: https://doc.qt.io/qt-5/signalsandslots.html
-
@jsulm said in variable transfer between two forms:
@fkaraokur You can use signals/slots for that: https://doc.qt.io/qt-5/signalsandslots.html
I studied here but could not figure out.
-
@fkaraokur Define a signal in the form class wich wants to expose that variable, in the other form define a slot and do:
connect(form1, &Form1::someSignal, form2, &Form2::someSlot);
If you then want to send that variable value to the other form simply emit the signal:
emit someSignal(variable);
If you have problems with that please ask more specific questions.
Signals/slots are one of the fundamental concepts in Qt which have to learn and understand if you want to use Qt. -
@fkaraokur said in variable transfer between two forms:
send the data in a variable from the first form to the second form
Solution also depends on just what/when you mean by this? For example, do you only want to initialise one form with data from another form? Is the other form a
QDialog
? Do you want get the data from a dialog only after the used has exited from it? -
@jsulm said in variable transfer between two forms:
@fkaraokur Define a signal in the form class wich wants to expose that variable, in the other form define a slot and do:
connect(form1, &Form1::someSignal, form2, &Form2::someSlot);
If you then want to send that variable value to the other form simply emit the signal:
emit someSignal(variable);
If you have problems with that please ask more specific questions.
Signals/slots are one of the fundamental concepts in Qt which have to learn and understand if you want to use Qt.connect(form1, &Form1::someSignal, form2, &Form2::someSlot);
Where should I write this expression? -
@fkaraokur said in variable transfer between two forms:
Where should I write this expression?
Where you have both form instances.