Link to my full code: https://www.dropbox.com/s/0tdnm2yd8038fwh/additem.py?dl=0
This is the error I get:
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'
Every goes well before I add:
self.buttonBox.accepted.connect(self.accept())
Calling this method:
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()
This is the rest of the code:
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
When you connect a signal to a slot you must pass it on behalf of the slot, the syntax is as follows
sender.signal.connect(receiver.slot)
In your case you must change:
self.buttonBox.accepted.connect(self.accept())
to:
self.buttonBox.accepted.connect(self.accept)
Note: When you pass the PyQt slot name you can invoke it, but if you pass the evaluated function it is impossible for it to do so.