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. Incorrectly passed from class to class
Forum Updated to NodeBB v4.3 + New Features

Incorrectly passed from class to class

Scheduled Pinned Locked Moved Unsolved General and Desktop
python
6 Posts 2 Posters 398 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.
  • S Offline
    S Offline
    sashup
    wrote on last edited by sashup
    #1

    The value is incorrectly passed from the ClassesPage1 class to the Parametrs class. The incorrectness is that:

    1. The window closes when I click on the select answer button
    2. In the second window (which should not be) everything is counted and displayed correctly. I commented out this line of code.
            from PyQt5 import QtWidgets, QtCore, QtGui
            from PyQt5.QtCore import Qt
            from PyQt5.QtGui import *
    
            import sys
    
            class ClassesPage1(QtWidgets.QWizardPage):
        def __init__(self, parent=None, mean=None, *args, **kwargs):
            super(ClassesPage1, self).__init__(parent=None, *args, **kwargs)
    
            self.label_2 = QtWidgets.QLabel("lbl1...", self)
            self.label_2.setAlignment(Qt.AlignCenter)
    
            self.label_3 = QtWidgets.QLabel("lbl2...", self)
            self.label_3.setAlignment(Qt.AlignLeft)
    
            self.checkBox_1 = QtWidgets.QCheckBox('cb1...')
            self.checkBox_2 = QtWidgets.QCheckBox('cb2...')
            self.checkBox_3 = QtWidgets.QCheckBox('cb3...')
            self.checkBox_4 = QtWidgets.QCheckBox('cb4...')
        
            self.label_5 = QtWidgets.QLabel('lbl3...')
    
            self.layout = QtWidgets.QVBoxLayout()
            self.layout.addWidget(self.label_2)
            self.layout.addWidget(self.label_3)
    
            self.layout.addWidget(self.checkBox_1)
            self.layout.addWidget(self.checkBox_2)
            self.layout.addWidget(self.checkBox_3)
            self.layout.addWidget(self.checkBox_4)
    
            self.layout.addWidget(self.label_5)
            self.setLayout(self.layout)
    
            self.checkBox_1.stateChanged.connect(self.check)
            self.checkBox_2.stateChanged.connect(self.check)
            self.checkBox_3.stateChanged.connect(self.check)
            self.checkBox_4.stateChanged.connect(self.check)
    
            self.listCheckBox = [self.checkBox_1, self.checkBox_2, self.checkBox_3, self.checkBox_4]
    
            self.a = 0
            self.parent = parent
            self.mean = 0
    
        def check(self):
            self.a = 0
            for checkBox in self.listCheckBox:
                if checkBox.isChecked():
                    self.a += 1
            self.mean = self.a / 4
    
            self.label_5.setText(f'Avarage: {self.mean}')
            self.parent._print()
    
        def nextId(self):
            return Wizard.class4
    
    
    
    class Parametrs(QtWidgets.QWizardPage):
        def __init__(self, *args, **kwargs):
            super(Parametrs, self).__init__(*args, **kwargs)
    
            self.par = ClassesPage1(self)
            #self.par.show()
            print(f'__init__: par.mean = {self.par.mean}')
    
        def _print(self):
            print(f'par.mean = {self.par.mean:.2f}')
    
        def nextId(self):
            return Wizard.classParametrs1
    
    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
    
        wizard = Wizard()
        wizard.show()
    
        sys.exit(app.exec_()) 
    
    jsulmJ 1 Reply Last reply
    0
    • S sashup

      The value is incorrectly passed from the ClassesPage1 class to the Parametrs class. The incorrectness is that:

      1. The window closes when I click on the select answer button
      2. In the second window (which should not be) everything is counted and displayed correctly. I commented out this line of code.
              from PyQt5 import QtWidgets, QtCore, QtGui
              from PyQt5.QtCore import Qt
              from PyQt5.QtGui import *
      
              import sys
      
              class ClassesPage1(QtWidgets.QWizardPage):
          def __init__(self, parent=None, mean=None, *args, **kwargs):
              super(ClassesPage1, self).__init__(parent=None, *args, **kwargs)
      
              self.label_2 = QtWidgets.QLabel("lbl1...", self)
              self.label_2.setAlignment(Qt.AlignCenter)
      
              self.label_3 = QtWidgets.QLabel("lbl2...", self)
              self.label_3.setAlignment(Qt.AlignLeft)
      
              self.checkBox_1 = QtWidgets.QCheckBox('cb1...')
              self.checkBox_2 = QtWidgets.QCheckBox('cb2...')
              self.checkBox_3 = QtWidgets.QCheckBox('cb3...')
              self.checkBox_4 = QtWidgets.QCheckBox('cb4...')
          
              self.label_5 = QtWidgets.QLabel('lbl3...')
      
              self.layout = QtWidgets.QVBoxLayout()
              self.layout.addWidget(self.label_2)
              self.layout.addWidget(self.label_3)
      
              self.layout.addWidget(self.checkBox_1)
              self.layout.addWidget(self.checkBox_2)
              self.layout.addWidget(self.checkBox_3)
              self.layout.addWidget(self.checkBox_4)
      
              self.layout.addWidget(self.label_5)
              self.setLayout(self.layout)
      
              self.checkBox_1.stateChanged.connect(self.check)
              self.checkBox_2.stateChanged.connect(self.check)
              self.checkBox_3.stateChanged.connect(self.check)
              self.checkBox_4.stateChanged.connect(self.check)
      
              self.listCheckBox = [self.checkBox_1, self.checkBox_2, self.checkBox_3, self.checkBox_4]
      
              self.a = 0
              self.parent = parent
              self.mean = 0
      
          def check(self):
              self.a = 0
              for checkBox in self.listCheckBox:
                  if checkBox.isChecked():
                      self.a += 1
              self.mean = self.a / 4
      
              self.label_5.setText(f'Avarage: {self.mean}')
              self.parent._print()
      
          def nextId(self):
              return Wizard.class4
      
      
      
      class Parametrs(QtWidgets.QWizardPage):
          def __init__(self, *args, **kwargs):
              super(Parametrs, self).__init__(*args, **kwargs)
      
              self.par = ClassesPage1(self)
              #self.par.show()
              print(f'__init__: par.mean = {self.par.mean}')
      
          def _print(self):
              print(f'par.mean = {self.par.mean:.2f}')
      
          def nextId(self):
              return Wizard.classParametrs1
      
      if __name__ == '__main__':
          app = QtWidgets.QApplication(sys.argv)
      
          wizard = Wizard()
          wizard.show()
      
          sys.exit(app.exec_()) 
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sashup said in Incorrectly passed from class to class:

      answer button

      Where is this button? Which windows closes?
      Please format your code properly.

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

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        @sashup said in Incorrectly passed from class to class:

        answer button

        Where is this button? Which windows closes?
        Please format your code properly.

        S Offline
        S Offline
        sashup
        wrote on last edited by
        #3

        @jsulm It is checkBox1, checkBox2, checkBox3 or checkBox4

        S 1 Reply Last reply
        0
        • S sashup

          @jsulm It is checkBox1, checkBox2, checkBox3 or checkBox4

          S Offline
          S Offline
          sashup
          wrote on last edited by
          #4

          @sashup In Parametrs

          ...
          self.par = ClassesPage1(self)
                  #self.par.show()
                  print(f'__init__: par.mean = {self.par.mean}')
          ...
          
          jsulmJ 1 Reply Last reply
          0
          • S sashup

            @sashup In Parametrs

            ...
            self.par = ClassesPage1(self)
                    #self.par.show()
                    print(f'__init__: par.mean = {self.par.mean}')
            ...
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @sashup Do you mean the window closes when check() is called, or what? Did you use debugger to see what happens?

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

            S 1 Reply Last reply
            0
            • jsulmJ jsulm

              @sashup Do you mean the window closes when check() is called, or what? Did you use debugger to see what happens?

              S Offline
              S Offline
              sashup
              wrote on last edited by
              #6

              @jsulm It looks like
              Безымянный1111.jpg

              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