How to update dateEdit from database
-
Hi,
I want to update dateEdit with a date from database but I have this error message. arguments did not match any overloaded call:
setDate(self, int, int, int): argument 1 has unexpected type 'str'. Below is the code I tried.dob = self.ui.dateEdit_4.date().setDate(data[10])
where data is my sql query. Please any help on what I'm doing wrong?
-
@LT-K101 said in How to update dateEdit from database:
self.ui.dateEdit_4.date().setDate(data[10])
QDateEdit.date()
returns the date in aQDateEdit
. You do not use it to set a date!setDate()
does that.self.ui.dateEdit_4.setDate(data[10])
But
setDate()
does not just accept a string, if that is what is coming back from your database (per the error message). (Why is your column for a date returning a string and not a date/datetime? It should be a datetime type column in the database and be returned as a date type in Qt/Python. I don't know what driver/query you are using.)You can probably use something like
self.ui.dateEdit_4.dateTimeFromText(data[10])
to convert your string to a date to be passed tosetDate()
. But that depends on the format of the string indata[10]
from the database, you may have to use some other method ofQDateTime
to parse your input string. Or Python has functions for converting strings to dates. -