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. class HMI to another class how make the dialog?
QtWS25 Last Chance

class HMI to another class how make the dialog?

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for python
8 Posts 4 Posters 710 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.
  • Z Offline
    Z Offline
    ZZR69
    wrote on 27 Apr 2021, 20:07 last edited by
    #1

    Hello,
    I am working on a graphical interface which uses the HMI class to control a widget lcdNumber.
    in another class i need to modify the value of lcdNumber but as I am no longer in the same class, the widget is no longer accessible and I have a message "self is not define).

    i don't know how can i do this ? (i just put a piece of code i didn't put all the variables and configuration so you can see more clearly)
    Thank you for your help

    code_text
    ```class HMI(QDialog):
        def __init__(self):
            super(HMI, self).__init__()
            loadUi('BAI.ui',self)
            self.checkBox.stateChanged.connect(self.Alstom2570) #Programme Alstom -25°C à 70°C valider appel de la fonction Alstom2570
            self.spinBox.valueChanged.connect(self.etuve)
            self.lcdNumber.display(count)    
            #stateChanged
    
    class Pi_hat_adc:
        def __init__(self,bus_num=1,addr=ADC_DEFAULT_IIC_ADDR):
            self.bus=Bus(bus_num)
            self.addr=addr
            print("adc")
    def Alstom2570class():
                   global count
                   while T < SB :  #tant quon est a froid (en dessous du seuil bas
            
                    GPIO.output(16, GPIO.HIGH)      #met la pin 16 à 1 (GPIO23)
            
                    count=count+1 #incrémentation de la variable count pour compter les démarrages
            
                    self.lcdNumber.display(count)
            
                    QtTest.QTest.qWait((TonF)) # on bloque la sortie GPIO a 1 pendant 15 min
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Apr 2021, 20:03 last edited by
      #2

      Hi,

      You can use signals and slots to communicate properly between your classes.

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

      Z 1 Reply Last reply 29 Apr 2021, 10:30
      0
      • S SGaist
        28 Apr 2021, 20:03

        Hi,

        You can use signals and slots to communicate properly between your classes.

        Z Offline
        Z Offline
        ZZR69
        wrote on 29 Apr 2021, 10:30 last edited by
        #3

        @SGaist I manage very well to do this in the same class on the other hand when it is necessary to pass from one class to another I do not know how to do it. do you have an example so i can understand? thank you

        J 1 Reply Last reply 29 Apr 2021, 11:55
        0
        • Z ZZR69
          29 Apr 2021, 10:30

          @SGaist I manage very well to do this in the same class on the other hand when it is necessary to pass from one class to another I do not know how to do it. do you have an example so i can understand? thank you

          J Offline
          J Offline
          JonB
          wrote on 29 Apr 2021, 11:55 last edited by
          #4

          @ZZR69
          You just need instances of the two classes you want to connect. Then:

          signalling_instance.signal_name.connect(slot_instance.slot_name)
          
          1 Reply Last reply
          1
          • Z Offline
            Z Offline
            ZZR69
            wrote on 29 Apr 2021, 19:03 last edited by
            #5

            Thanks a lot,
            for exemple in my code if i run like that i have error message on line :

            code_text
            ``` self.lcdNumber.display(count)" self is not defined.
            

            So i have try to replace this ligne by :

            self.HMI.lcdNumber.connect(self.display(count))
            and new error is : self.HMI.lcdNumber.connect(self.display(count))
            AttributeError: 'Pi_hat_adc' object has no attribute 'HMI'

            in fact i try to write the "count" variable of lcdNumber widget where is in class HMI

            J 1 Reply Last reply 30 Apr 2021, 06:26
            0
            • Z ZZR69
              29 Apr 2021, 19:03

              Thanks a lot,
              for exemple in my code if i run like that i have error message on line :

              code_text
              ``` self.lcdNumber.display(count)" self is not defined.
              

              So i have try to replace this ligne by :

              self.HMI.lcdNumber.connect(self.display(count))
              and new error is : self.HMI.lcdNumber.connect(self.display(count))
              AttributeError: 'Pi_hat_adc' object has no attribute 'HMI'

              in fact i try to write the "count" variable of lcdNumber widget where is in class HMI

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 30 Apr 2021, 06:26 last edited by
              #6

              @ZZR69 said in class HMI to another class how make the dialog?:

              self.lcdNumber.display(count)" self is not defined.

              Well, you seem to call this in a function which is not a method. Please show the code where you call this...

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

              1 Reply Last reply
              1
              • Z Offline
                Z Offline
                ZZR69
                wrote on 30 Apr 2021, 16:08 last edited by
                #7

                thanks , here you are the start code with HMI class where i write 0 in lcdNumber :

                class HMI(QDialog):
                    def __init__(self):
                        super(HMI, self).__init__()
                        loadUi('BAI.ui',self)
                        self.checkBox.stateChanged.connect(self.Alstom2570) #Programme Alstom -25°C à 70°C valider appel de la fonction Alstom2570
                        self.spinBox.valueChanged.connect(self.etuve)
                        self.lcdNumber.display(count)    
                        #stateChanged
                

                After i have create a function called alstom2570()

                def Alstom2570(self): #Fonction appele lors de la selection du programme Alstom -25°C à 70°C
                        #Toutes les variables sont declare et initialise pour correspondre au programme T2
                        print("case coche")#debug
                        global SB #definition de la variable SB (temperature seuil bas mise ss tension)
                        global SH #definition de la variable SH (temperature seuil haut mise ss tension)
                        SB=600 #variable definissant le seuil de temperature basse (si la temperature etuve descend sous -20°C mise ss tension)-20°C=600mV
                        SH=3001 #variable definissant le seuil de temperature haute (si la temperature etuve depasse 65°C mise ss tension) 65°C=3001mV
                        ####on choisis -20 et 65 afin d etre sur que l etuve arrive a ces temperature et quil n'y ai pas doscillation de temperature
                        ###ayant pour effet des demarrages alleatoirs
                        global TonF
                        TonF=15*60000 #Temps ON 15min en ms (mise ss tension) a froid (seuil bas)
                        global ToffF
                        ToffF=15*60000 #Temps OFF 15min (mise hors tension) à froid (seuil bas)
                        global T
                        #T=-25 #uniquement pour debug ensuite T sera la value par ladc
                        print("appel programme alstom2570")
                        
                        Alstom2570class() #appel de la fonction permettant de sortir de class interface graphique Qt
                        
                

                in this function i call anoter function named Alstom2570class and here i need to write in lcdNumber :

                self.lcdNumber.display(count)
                
                

                but i can't acces to lcdNumber in this function...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 30 Apr 2021, 18:46 last edited by
                  #8

                  If that:
                  @ZZR69 said in class HMI to another class how make the dialog?:

                  Alstom2570class() #appel de la fonction permettant de sortir de class interface graphique Qt

                  refers to:
                  @ZZR69 said in class HMI to another class how make the dialog?:

                  def Alstom2570class()

                  then you have an issue in your understanding of how Python classes work as well as the signals and slots concept of Qt.

                  I would recommend to take a step back and start with a minimal application showing a QSpinBox and a QLabel. Then connect the spin box to a slot that will update the QLabel with its value. Once you have that working, you'll be able to implement your application.

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

                  1 Reply Last reply
                  0

                  2/8

                  28 Apr 2021, 20:03

                  6 unread
                  • Login

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