0

I have a QString which contains some unicode chars, and I want to convert the QString to a QByteArray. (Which is later converted back to a QString)

If I use toLatin, toUtf8 or toLocal8bit the unicode characters are lost upon conversion.

How to I convert these unicode character filled QString to a QByteArray?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
TSG
  • 4,242
  • 9
  • 61
  • 121
  • _UTF-8 is a Unicode codec and can represent all characters in a Unicode string_, so `QString::toUtf8` should be a lossless encoding according to the docs, https://doc.qt.io/qt-6/qstring.html#toUtf8, if you have evidence contradicting this statement you can file a bug – absolute.madness Aug 14 '22 at 19:09
  • 1
    How do you know that some unicode characters were lost? By printing it out to console? This does not necessarily mean it was lost because console itself has certain encoding which may be different than the encoding you are sending to it... – HiFile.app - best file manager Aug 14 '22 at 20:01
  • By inspecting the QByteArray in the debugger. Though there may be an explanation (that I founds elsewhere I must test first). If resolved I'll post answer. – TSG Aug 14 '22 at 21:37

0 Answers0