PDA

View Full Version : [SOLVED] QDate is giving a different date



xeroblast
7th December 2010, 03:44
hi,

i have a weird problem regarding on QDate. this is the code :



QString strDate = "April 01, 1981";
QDate date = QDate::fromString(strDate);


when i tried to display it again using date.toString("MMMM dd yyyy") = September 14 1752. what happened to my date?

ChrisW67
7th December 2010, 03:54
The conversion failed. You are telling QDate::fromString() to use the format Qt::TextDate (http://doc.qt.nokia.com/latest/qt.html#DateFormat-enum) but feeding in a date that is not in that format. You want to adjust your string format, or use the other variant of the fromString() method and specify how the string should be interpreted.

xeroblast
7th December 2010, 04:00
yeah.. thanx for the reply. it should be : QDate date = QDate::fromString(strDate, "MMMM dd, yyyy"). the Qt::TextDate must be the correct format of the string date.