[英]QlineEdit::text() not returning the text entered when push button is clicked and the object name of that particular QlineEdit is lineEdit
我在Alert.ui
文件中創建了三個LineEdits
。 我的第一個LineEdit
對象名稱lineEdit
從那里我需要時閱讀文本pushButton
被點擊。 但是,當我通過打印單詞的到達率進行檢查時,我知道即使該lineEdit
的文本已從空白更改為某個值,它也永遠不會進入onChanged
方法。 我不明白為什么會這樣。
import MySQLdb
import sys
from PyQt4 import QtCore, QtGui, uic
qtCreatorFile = "Alert.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
QtGui.QWidget.__init__(self)
self.setupUi(self)
self.lineEdit=QtGui.QLineEdit(self)
print("reach")
self.pushButton.clicked.connect(self.pushButton_clicked)
def pushButton_clicked(self):
self.lineEdit = QtGui.QLineEdit(self)
self.lineEdit.textChanged.connect(self.onClicked)
def onClicked(self,text):
ID=text
print(ID)
if __name__==_main_:
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
我仍然不確定您的代碼中發生了什么,但是乍一看,我可以發現以下問題:
您永遠不會將第一個QLineEdit連接到onClicked
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.