Issue
I've been trying to create a program that registers and logs in a user, the register part should store the details into a database but I've experienced a bit of trouble with taking input from the QT text box and inserting it into my database. It doesn't take any input from the text box, so I've tried to use qtsql to help me input data, but I can't manage to get it working.
#Register
def InsertData(self):
db=QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("/home/user/test.db")
if db.open():
query=QSqlQuery
query.exec_("INSERT INTO users(email_address,password) VALUES(?,?)",self.password.text,self.email.text)
db.commit()
db.close()
Solution
You can‘t get the value in your SQL statement, because you are not calling the object for password and email
Try:
val_password = self.password.text()
val_email = self.email.text()
query.exec_("INSERT INTO users(email_address,password) VALUES(?,?)",val_password, val_email)
I‘m not used to qtsql, but in sqlite you also have to assign a cursor to your sql connection, you might also want to check that.
Answered By - user14757127
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.