Calling a lineEdit value from one form to another form
-
I want to call the LineEdit value (id_no) from form A on form B and C. Each form has a unique content and a unique database table. Any assistance please?Thanks in advance.
class MainWindow(QtWidgets.QMainWindow): def __init__(self, mainMenu): global new_id_no new_Id_no= id_no super(MainWindow, self).__init__() self.mainMenu = mainMenu self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.First_Add_Button.clicked.connect(self.Form_A) self.ui.Second_Add_Button.clicked.connect(self.Form_B) self.ui.Third_Add_Button.clicked.connect(self.Form_C) def Form_A(self): id_no = self.ui.lineEdit.text() name = self.ui.lineEdit_1.text() def Form_B(self): address = self.ui.lineEdit_2.text() city = self.ui.lineEdit_3.text() def Form_C(self): country = self.ui.lineEdit_4.text()
-
@LT-K101 said in Calling a lineEdit value from one form to another form:
call the LineEdit value (id_no)
Don't know what "calling" a line edit or its value means. Your "Form"s are just methods in class
MainWindow
, no other classes here. Your variables inside the methods (id_no
,address
, etc.) are just local variables in the methods, so they are irrelevant for the outside world. There is nothing here to use other than the necessaryself.ui.lineEdit_someNumber
from no matter which method. Unless you want to do something about rewriting your code, like utility getters (or you could use a Python@property
decorator if you prefer):def address(): return self.ui.lineEdit_2.text()
Or maybe
def Form_A(self): self.id_no = self.ui.lineEdit.text()
but that is not clever coding practice.
The logic of whatever you intend by calling
self.Form_A
fromFirst_Add_Button.clicked
is not clear, as it stands it accomplishes nothing. -
@LT-K101 said in Calling a lineEdit value from one form to another form:
I declared it as a global variable and it worked.
I know, but that is so not the way to do it!
I don't begin to have the time to show & teach you what you should be doing, I'm afraid....