lundi 4 décembre 2017

How to convert std::string to QString preserving ASCII values and vice versa?

I am dealing with std::strings, in low level processing so I have to manipulate bits of characters of that string.
Also I have to show the results using GUI by viewing the result on QPlainTextEdit, as they may be copied for reverse processing.
so I deal with strings and results like 0xe3 may occur. and when I convert the std::string to QString to be shown in the GUI and vice versa. I use,

 QString::fromStdString(myString); // to convert std::string to QString
 myQString.toStdString();          // to convert back from QString to std::string

The problem is that when values result from processing on the string. after converting it to QString and try to convert it back, values change.
I mean the ASCII value of each character,for example

0x3f becomes 0xbd, and 0xe3 becomes 0xef

I guess the problem happens due to encoding issues between std::string and QString, but I can not figure out how to deal with it or how to get the right values from QString.

Aucun commentaire:

Enregistrer un commentaire