regex - Problems to convert a QString to QDateTime -
i have problem convert qstring qdatatime-object.
the string looks like: "2008:09:23 14:18:03 , have length of 20. problem is, if remove first character output looks like: "008:09:23 14:18:03.
that's wrong it? can delete characters without numbers?
the code:
qdatetime date; qstring d=qstring::fromstdstring(result.val_string); date.fromstring(d,"yyyy:mm:dd hh:mm:ss"); qdebug()<<d; qdebug()<<d.length()<<date.tostring(); and output:
"008:09:23 14:18:03 19 "" greetings
the double quotes printed qdebug, not included in qstring itself. however, seems have non-printable character @ end of original string deletes closing " sign. try copy first 19 characters qstring:
qstring d = qstring::fromstdstring(result.val_string.substr(0, 19)); date.fromstring(d,"yyyy:mm:dd hh:mm:ss"); qdebug()<<d; qdebug()<<d.length()<<date.tostring(); edit qdatetime.fromstring static method returning qdatetime object - not modify object itself!
qdatetime date; std::string val_string = "2008:09:23 14:18:03"; qstring d = qstring::fromstdstring(val_string.substr(0, 19)); date = qdatetime::fromstring(d,"yyyy:mm:dd hh:mm:ss"); qdebug()<<d; qdebug()<<d.length()<<date.tostring();
Comments
Post a Comment