How can I set the date of a QDateComboBox using a string that some times can also be empty?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you’re talking about QDateEdit, you will need to create a QDate object from the string so that it can be passed to the setDate function.
The QDate class has a static fromString function that can create a QDate from a string, but you will have to know the format of the date in the string for it to work properly.
By default,
QDate.fromStringassumes dates will be in the following format:However, you can specify a format as the second argument to
fromStringby passing either a standard DateFormat, or a custom format string.If QDate can’t parse the date-string, an invalid QDate object will be returned (you can check this with
date.isValid()).An empty string will produce an invalid date object, but if you pass one to
QDateEdit.setDate, it will be ignored (i.e. the date won’t change).