Python 属性错误:';用户界面对话框';对象没有属性';lineEdit_3';

Python 属性错误:';用户界面对话框';对象没有属性';lineEdit_3';,python,pyqt,pyqt4,Python,Pyqt,Pyqt4,链接到我的完整代码: 这是我得到的错误: File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 187, in <module> ui = Ui_Dialog() File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 23, in __init__ self.setupUi(self) Fi

链接到我的完整代码:

这是我得到的错误:

  File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 187, in <module>
    ui = Ui_Dialog()
  File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 23, in __init__
    self.setupUi(self)
  File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 66, in setupUi
    self.buttonBox.accepted.connect(self.accept())
  File "C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py", line 169, in accept
    brandName = self.lineEdit_3.text()
AttributeError: 'Ui_Dialog' object has no attribute 'lineEdit_3'
调用此方法:

def accept(self):
    conn = sqlite3.connect('inventory.db')
    c = conn.cursor()

    unix = time.time()
    dateUpdated = datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S')
    company = self.lineEdit_2.text()
    brandName = self.lineEdit_3.text()
    genericName = self.lineEdit_4.text()
    purchasePrice = self.lineEdit_5.text()
    category = self.lineEdit_6.text()
    sellingPrice = purchasePrice * sellingFactor
    quantity = self.lineEdit_7.text()
    #dosageForm = self.lineEdit_9.text()
    expiryDate = self.lineEdit_10.text()

    c.execute(
        "INSERT INTO inventory(dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
        (dateUpdated, company, brandName, genericName, category, purchasePrice, sellingPrice, quantity, expiryDate))
    conn.commit()
以下是代码的其余部分:

app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()

ui = Ui_Dialog()
ui.setupUi(window)

window.show()
sys.exit(app.exec_())

将信号连接到插槽时,必须代表插槽传递信号,语法如下

sender.signal.connect(receiver.slot)
在您的情况下,您必须更改:

self.buttonBox.accepted.connect(self.accept())
致:


注意:当您传递PyQt插槽名称时,您可以调用它,但是如果您传递经过计算的函数,它就不可能这样做。

非常感谢@eyllanesc!如果看不到
C:/Users/Lloyd/Desktop/Python Projects/stock/additem.py
,很难猜测。“但很可能不存在这样的属性。”托马斯基利安说,艾伦内斯克已经回答了这个问题。
self.buttonBox.accepted.connect(self.accept())
self.buttonBox.accepted.connect(self.accept)