Cyrillians in the file.
-
How do you put a Cyrillian in the file? Looking at the forums, they're only offering to give up the Cyrillians and write everything in a translite or Latin. I'd like a working example.
-
Example with different text codings:
QFile file("file.txt"); if (file.open(QFile::WriteOnly | QFile::Text)) { QTextStream stream(&file);
stream.setCodec("UTF-8"); stream << tr("Строка в UTF-8\n"); stream.flush(); stream.setCodec("Windows-1251"); stream << tr("Строка в Windows-1251\n"); stream.flush();
}
stream.flush()
I need a summer code to change. If you don't do that, the whole text will be in the last, put-in, code. In reality, this is generally not required.UPDATE for Qt À0
The origins must be in UTF-8. In addition, globally encoding for
tr
:QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
If the original texts are in other codings, another code shall be applied accordingly.
tr
e.g.:QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251"));
UPDATE for Qt grad= 5.0
Starting with Qt 5.0, the guys "coding" solved the coding problem. Everything must be in UTF-8 and that's it. As a result, everyone was drank from the source.
QTextCodec::setCodecForXXX
exceptQTextCodec::setCodecForLocale
♪For Qt’s own source code, we have decreed that the source should be
UTF-8 only, and so I proceeded a few weeks ago to find and recode all
non-UTF-8 sources. And I’m going even further than that: if you don’t
use UTF-8 for your source code, you’ll be on your own. Though it’s
possible to make it work, do not ask us for help and do not expect us
to add convenience functions. I am also discarding any arguments of
the form “my editor/IDE/OS/environment does not support UTF-8 ' .The original can be seen in Thiago Macieira's blog: http://www.macieira.org/blog/2012/05/source-code-must-be-utf-8-and-qstring-wants-it/