Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. get a value from secondary window and use it in main window
Forum Updated to NodeBB v4.3 + New Features

get a value from secondary window and use it in main window

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 567 Views 2 Watching
  • 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.
  • P Offline
    P Offline
    Praanesh
    wrote on last edited by
    #1

    I have two windows. when I click a pushbutton in GUIWindow, it opens the settings window. The attribute 'new' is populated in the Settings_window. Now, I want the value stored in the attribute 'new' in class Settings_window to be used in the class GUIWindow. How do I do that? below is the code I wrote but when I run this I get an error saying Settings_window has no attribute 'new'. Can someone please help me resolve this issue.

    device_id_lm_x = 4
    device_id_lm_y = 5
    device_id_lm_z = 6
    class Settings_window(qtw.QWidget):
    
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.sw = Ui_settings()
            self.sw.setupUi(self)
    
            self.sw.radio_lm_x_button.clicked.connect(self.choose_device_id)
            self.sw.radio_lm_y_button.clicked.connect(self.choose_device_id)
            self.sw.radio_lm_z_button.clicked.connect(self.choose_device_id)
    
            self.sw.set_button.clicked.connect(lambda: self.set_border(self.device_id))
    
        def choose_device_id(self):
            if self.sw.radio_lm_x_button.isChecked():
                self.device_id = device_id_lm_x
                print(self.device_id)
            elif self.sw.radio_lm_y_button.isChecked():
                self.device_id = device_id_lm_y
                print(self.device_id)
            elif self.sw.radio_lm_z_button.isChecked():
                self.device_id = device_id_lm_z
                print(self.device_id)
    
        def set_border(self, device_id):
            self.new = 1234
        
    class GUIWindow(qtw.QWidget):
    
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.ui = Ui_Form()
            self.ss = Settings_window()
            self.ui.setupUi(self)
    
            self.ui.new_button.clicked.connect(lambda: self.new_val(self.ss.new))
        
        def new_val(self, value):
            print(value)
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Until set_border has been called, Settings_window has not attribute named new.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Until set_border has been called, Settings_window has not attribute named new.

        P Offline
        P Offline
        Praanesh
        wrote on last edited by Praanesh
        #3

        @SGaist Hi, I want the value in the attribute name 'new' that is populated in set_border method. That is where my attribute gets its value and I want to use that value in the main window.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That I understood. However, the way you implemented it can't work.

          When you click on "new_button", you are directly requesting the value of new from your Settings_window object which does not exists since it's only created in set_border.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          0
          • SGaistS SGaist

            That I understood. However, the way you implemented it can't work.

            When you click on "new_button", you are directly requesting the value of new from your Settings_window object which does not exists since it's only created in set_border.

            P Offline
            P Offline
            Praanesh
            wrote on last edited by
            #5

            @SGaist How else can I get the value from the attribute 'new' in the GUIWindow. can you please show me an example

            jsulmJ 1 Reply Last reply
            0
            • P Praanesh

              @SGaist How else can I get the value from the attribute 'new' in the GUIWindow. can you please show me an example

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Praanesh said in get a value from secondary window and use it in main window:

              How else can I get the value from the attribute 'new' in the GUIWindow

              Set self.new in constructor. It's really that simple...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              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