Python QLineEdit在几个屏幕后被删除

Python QLineEdit在几个屏幕后被删除,python,pyqt5,Python,Pyqt5,我正在使用QLineEdit,然后需要在PyQt中的两个屏幕之后引用它。然而,当我提到它时,我总是不断地得到这个错误 回溯最近一次呼叫上次: passwordmissing2ndscreenverify中的文件[filename],第227行 P1=self.entrypasswordmissingscreen1.text 运行时错误:已删除QLineEdit类型的包装C/C++对象 这是我第一次使用Qt来创建复杂的程序,这些程序引用了以前几个屏幕上的内容,如果有人能提供帮助,我将不胜感激 以下

我正在使用QLineEdit,然后需要在PyQt中的两个屏幕之后引用它。然而,当我提到它时,我总是不断地得到这个错误

回溯最近一次呼叫上次: passwordmissing2ndscreenverify中的文件[filename],第227行 P1=self.entrypasswordmissingscreen1.text 运行时错误:已删除QLineEdit类型的包装C/C++对象

这是我第一次使用Qt来创建复杂的程序,这些程序引用了以前几个屏幕上的内容,如果有人能提供帮助,我将不胜感激

以下是该部分的代码:

def passwordmissing1stscreen(self):
    #layouts
    self.mainLayout=QtWidgets.QVBoxLayout()
    self.secondaryLayout=QtWidgets.QHBoxLayout()

    #Labels
    self.passwordMissing1stScreenlabel= QtWidgets.QLabel("Please enter the new password")

    #buttons
    self.cancelbutton=QtWidgets.QPushButton("Cancel", self)
    self.okButton=QtWidgets.QPushButton("OK", self)
    #input
    self.entrypasswordmissingscreen1 = QtWidgets.QLineEdit()
    P1 = self.entrypasswordmissingscreen1.text()
    #conections
    self.cancelbutton.clicked.connect(self.exit)
    self.okButton.clicked.connect(self.passwordmissing2ndscreen)

    #add to layouts
    self.mainLayout.addWidget(self.passwordMissing1stScreenlabel)
    self.mainLayout.addWidget(self.entrypasswordmissingscreen1)
    self.secondaryLayout.addWidget(self.okButton)
    self.secondaryLayout.addWidget(self.cancelbutton)
    self.mainLayout.addLayout(self.secondaryLayout)


    #display screen#
    self.mainViewWidget = QtWidgets.QWidget()
    self.mainViewWidget.setLayout(self.mainLayout)
    self.setCentralWidget(self.mainViewWidget)



def passwordmissing2ndscreen(self):
    #layouts
    self.mainLayout=QtWidgets.QVBoxLayout()
    self.secondaryLayout=QtWidgets.QHBoxLayout()

    #Labels
    self.passwordMissing2ndScreenlabel= QtWidgets.QLabel("Please enter the new password again")

    #buttons
    self.cancelbutton=QtWidgets.QPushButton("Cancel", self)
    self.okButton=QtWidgets.QPushButton("OK", self)

    #input
    self.entrypasswordmissingscreen2=QtWidgets.QLineEdit()


    #add to layouts
    self.mainLayout.addWidget(self.passwordMissing2ndScreenlabel)
    self.mainLayout.addWidget(self.entrypasswordmissingscreen2)
    self.secondaryLayout.addWidget(self.okButton)
    self.secondaryLayout.addWidget(self.cancelbutton)
    self.mainLayout.addLayout(self.secondaryLayout)
    #conections
    self.cancelbutton.clicked.connect(self.exit)
    self.okButton.clicked.connect(self.passwordmissing2ndscreenverify)

    #display screen#
    self.mainViewWidget = QtWidgets.QWidget()
    self.mainViewWidget.setLayout(self.mainLayout)
    self.setCentralWidget(self.mainViewWidget)

def passwordmissing2ndscreenverify(self):
    P1=self.entrypasswordmissingscreen1.text()
    P2=self.entrypasswordmissingscreen2.text()
    print (P1)
    print (P2)

好的,在与朋友和其他程序员讨论之后,我们发现了一个非常有效的解决方案,它没有让P1=self.entryPasswordMissingScreen 1.text在passwordmissing1stscreen中,而是将self.P1.entryPasswordMissingScreen 1.text放在passwordmissing2ndscreen中,并将对P1的所有引用更改为self.P1