Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt 5.2.1: cannot parse date/time

I am having a problem in parsing a date from QString using Qt 5.2.1...

I am using the following code:

QString value = "1979-10-27T04:00:00.000";
QDateTime dt = QDateTime::fromString(value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'zzz");

but the returned QDateTime is invalid... what am I doing wrong?

like image 853
Morix Dev Avatar asked Mar 08 '26 21:03

Morix Dev


2 Answers

This is likely due to the following bug in Creator:

GDB pretty printer for QDateTime is broken, shows “(invalid)” even when QDateTime is not invalid

According to the latest comment (01/Apr/14), it now displays a valid date until it's expanded:

It looks much better now. QDateTime shows a human-readable format. Only when I try to expand it, it becomes "not accessible".

I'd recommend upgrading your version of Creator.

With as many users as Qt has, you'll often find existing bug reports for your problem if you have a quick search through Jira.

like image 51
Mitch Avatar answered Mar 10 '26 11:03

Mitch


Thank you guys for you help: I think that the problem is definitively related to QtCreator (or at least to the debugger)...

I said that the QDateTime was not valid because the expression watch of QtCreator told me so (as you can see from the screenshot here below)... But if I qDebug() my datetime, then it appears correct...

Screenshot from my PC

like image 32
Morix Dev Avatar answered Mar 10 '26 13:03

Morix Dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!