8 with no signature file encoding
I'm using Qt5 along with Visual Studio 2012 and recently wrote a logger class, which basically redirect string streams to the file. The other day I realised that there is no "special" characters support (eg. polish, german, russian).
qDebug() << "Special characters: ąężźćłóĄĘŻĆŁÓ";
Is producing the following output:
Special characters: �꿟����ʯƣ�
I have tried multiple Unicode settings listen in File
-> Advanced Save Options
.
However, there is no option to save the file without the BOM
signature and I think that might be the issue, since when I change the file encoding through the Notepad++ to UTF-8 (without BOM)
, then compile, everything is working fine... unfortunately until I make any changes in the Visual Studio.
I have also tried setting compiler encoding to Unicode:
Is there any solution for Visual Studio to change the encoding to UTF-8 without BOM signature?
Code snippet which writes to file:
file = new QFile;
file->setFileName(fileName);
file->open(QIODevice::Append | QIODevice::Text);
[..]
QTextStream out(file);
out.setCodec("UTF-8");
out << QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") << value << "n";
I've been also trying using value.toUtf8()
.
After many unsuccessful tries, I have two possibilities to fix the encoding issue:
This one is suggested by @MrEricSir in the comments. The idea is to use QStringLiteral
function on string containing special characters.
Like this: QStringLiteral("ąśżęłóĄŚŻĘŁÓ");
I personally picked the first method since it don't force me to keep using additional functions everytime I'd like to print special characters. In both cases, results are the same.
Thanks for everyone who posted a comment and tried to help.
链接地址: http://www.djcxy.com/p/33364.html下一篇: 8没有签名文件编码