monochrome
monochrome

Reputation: 25

How to inherit a variable from another classes method

class CreateAcc(QDialog):

def __init__(self):
    super(CreateAcc,self).__init__()
    loadUi("createacc.ui",self)
    self.confirmacc.clicked.connect(self.createaccfunction)
    self.password.setEchoMode(QtWidgets.QLineEdit.Password)
    self.confirmpass.setEchoMode(QtWidgets.QLineEdit.Password)
    self.invalid.setVisible(False)
    
    

def createaccfunction(self):

    email = self.email.text()
    tc = email
    now = datetime.now()
    d1 = now.strftime("%Y  %m  %d  %H %M")

    if self.password.text()==self.confirmpass.text() and len(email)>=11:   #exception won't work here!!#
        password = self.password.text()
        #datatc = {email : }
        #datapass = {"password" : password}
        db.child("Registered_Users").child(tc).child(d1)
        #db.child("Registered_Users").child("HMI_USER").child("HMI").push(datapass)
        login = Login()
        widget.addWidget(login)
        widget.setCurrentIndex(widget.currentIndex() + 1)
    else:
        self.invalid.setVisible(True)


class Measure(QDialog):

def __init__(self):
    super(Measure,self).__init__()
    loadUi("measure.ui",self)
    widget.setFixedWidth(1022)
    widget.setFixedHeight(744)
    self.bodytmpBtn.clicked.connect(self.bodyTemp)

def bodyTemp(self):

    i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
    mlx = adafruit_mlx90614.MLX90614(i2c)
    target_temp = "{:.2f}".format(mlx.object_temperature)
    datatemp = {CreateAcc.d1 : target_temp}
    db.child("Registered_Users").child(CreateAcc.tc).child(CreateAcc.d1).push(datatemp)

Hello friends. The code you have seen is part of my graduation project. I need to get the variables from CrateAcc class to write my Firebase server in the same name that crated account before. In measure class I need to get that "tc" and "d1" variables.

Upvotes: 0

Views: 168

Answers (1)

Neb
Neb

Reputation: 2280

You should pass the variable that you need to the Measure constructor. Hence, the class definition should be something like this:

class Measure(QDialogue):
    def __init__(self, tc, d1, *args, **kwargs):
         super(Measure, self).__init__(*args, **kwargs)
         
         self.tc = tc
         self.d1 = d1

         # do other stuff 

Then, to pass the parameters:

acc = CreateAcc()
acc.createaccfunction()

# here you instantiate the new object passing those parameters
measure = Measure(acc.tc, acc.d1)

Upvotes: 1

Related Questions