Problem with encoding
-
Hi guys.
I am having a problem with, I think, the encoding in Qt. I try to write a file with some symbols but it seems that Qt is not able to read them and instead replaces them with "?". The symbol I need in particular is "¬". I realize that something is weird before writing the file, as doing qDebug() already shows the change.
Here is an example:tmp.push_front("¬"); qDebug() << tmp;
Where tmp is qString and when doing qDebug it shows a "?" where there should be a "¬".
I tried so many encodings (UTF-8,UTF-16,ISO-8859) yet no one seems to work.
I am changing this in Tools > Options >Text Editor > Behaviour > Default encoding.Thanks!
-
@danifujii
This is - as you already noticed - a very error prone approach. Since it heavily depends on the file encoding you are using. The next developer may save the file in another encoding in the worst case.So you should use the unicode value directly:
QChar(0x00AC) // or QString::fromUtf8("\u00AC")
-
@raven-worx Oh thank you! Didn't even think about doing something like that. It worked perfectly, thanks!