Important: Please read the Qt Code of Conduct -

[RESOLVED] Problem of string conversion

  • Hi,
    I have a software that exchanges data with a web server. One request I send to the server is to obtain the name of an user. Unfortunately, I have a case with a (french) name that is "Jérémie". THen, the answer I receive is "J\u00e9r\u00e9mie". So it is a mix between ASCII characters and a code (in ASCII) indicating an Unicode part.

    SO, my question is "how to convert this ASCII string in the QString "Jérémie"?"

    Thanks for your help.

  • Moderators

    There's nothing ready-made for that in Qt. You can find all "\uXXXX" strings (either with QString methods or QRegularExpression), convert the XXXX to a number with QString::toInt() and replace the whole thing with QChar(theNumber).

    The easier way (if you control the server) would be to modify your service to return a utf encoded characters and not the string notation of them.

  • Thanks for the answer. I will implement the manual solution.

Log in to reply