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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -