Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling a lineEdit value from one form to another form

Calling a lineEdit value from one form to another form

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 277 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by
    #1

    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()
            
    
    
    
    
    
    
    JonBJ 1 Reply Last reply
    0
    • L LT-K101

      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()
              
      
      
      
      
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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 necessary self.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 from First_Add_Button.clicked is not clear, as it stands it accomplishes nothing.

      L 1 Reply Last reply
      0
      • JonBJ JonB

        @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 necessary self.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 from First_Add_Button.clicked is not clear, as it stands it accomplishes nothing.

        L Offline
        L Offline
        LT-K101
        wrote on last edited by
        #3

        @JonB Thanks for your response . I want to pass the id_no to the other forms database. I declared it as a global variable and it worked.

        JonBJ 1 Reply Last reply
        0
        • L LT-K101

          @JonB Thanks for your response . I want to pass the id_no to the other forms database. I declared it as a global variable and it worked.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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....

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved