3

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?

Morix Dev
  • 2,700
  • 1
  • 28
  • 49

2 Answers2

2

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.

Moog
  • 10,193
  • 2
  • 40
  • 66
Mitch
  • 23,716
  • 9
  • 83
  • 122
1

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

Morix Dev
  • 2,700
  • 1
  • 28
  • 49