QTextCodec::setCodecForCStrings is GONE in Qt5

2020-07-09 03:21发布

问题:

All displayed text in my project is in Greek. I didn't use tr(), just Greek characters directly. And for the correct encoding I was using:

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("ISO 8859-7"));//for Greek

Qt5 took setCodecForCStrings away , and all the characters are displayed as "???????". Is there a workaround?

Please note this is a big project, I want to avoid using code for every string in the program.

回答1:

Thank you Esailija

So saving all my files with UTF-8 encoding solved the problem.

If you are using Qt Creator, change the default encoding to UTF-8:
Preferences -> Text Editor -> Default Encoding ... choose UTF-8
Then for the existing files go to Edit->Select Encoding and change it to UTF-8

also for anyone wanting more details look here http://www.macieira.org/blog/2012/05/source-code-must-be-utf-8-and-qstring-wants-it/



标签: unicode qt5