QLineEdit在几个屏幕后被删除

时间:2015-01-31 09:54:14

标签: python pyqt5

我正在使用QLineEdit然后需要在PyQt中的2个屏幕之后引用它。但是,当我引用它时,我一直都会遇到这个错误

Traceback (most recent call last): File "[filename]", line 227, in passwordmissing2ndscreenverify P1=self.entrypasswordmissingscreen1.text() RuntimeError: wrapped C/C++ object of type QLineEdit has been deleted

这是我第一次使用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)

1 个答案:

答案 0 :(得分:0)

好的,经过与朋友和其他程序员的一些讨论后,我们遇到了一个完美的解决方案,而不是在passwordmissing1stscreen中使用P1 = self.entrypasswordmissingscreen1.text(),而是将self.P1.entrypasswordmissingscreen1.text()放入passwordmissing2ndscreen并获得{{1}的所有引用}已更改为P1