将Qt默认编码设置为UTF-8 [英] Set Qt default encoding to UTF-8
问题描述
在我的Qt应用程序中,我的源代码文件编码为UTF-8。对于以下代码...
QMessageBox :: critical(this,Nepoznatapogreška,Dogodila se nepoznatapogreška! li zatvoriti ovaj program?,QMessageBox :: Yes,QMessageBox :: No);
...当我显示该消息框时,字符š不会显示为š,但是有点奇怪。这是因为Qt转换所有的C字符串,就好像它们是使用LATIN-1编码的。为了解决这个问题,我一直在使用:
QMessageBox :: critical(this,QString :: fromUtf8(Nepoznatapogreška) ,QString :: fromUtf8(Dogodila se nepoznatapogreška!Želiteli zatvoriti ovaj program?),QMessageBox :: Yes,QMessageBox :: No);
有没有办法摆脱所有调用 QString ::您是否尝试过使用 .qt.io / qt-4.8 / qtextcodec.html#setCodecForCStringsrel =nofollow> QTextCodec :: setCodecForCStrings(QTextCodec :: codecForName(UTF-8))?
In my Qt application my source code files are encoded as UTF-8. For the following code...
QMessageBox::critical(this, "Nepoznata pogreška", "Dogodila se nepoznata pogreška! Želite li zatvoriti ovaj program ?", QMessageBox::Yes, QMessageBox::No);
...when I show that message box, the character "š" wouldn't be displayed as "š", but as something strange. This is because Qt converts all C-strings as if they are encoded using LATIN-1. To solve this I've been using:
QMessageBox::critical(this, QString::fromUtf8("Nepoznata pogreška"), QString::fromUtf8("Dogodila se nepoznata pogreška! Želite li zatvoriti ovaj program ?"), QMessageBox::Yes, QMessageBox::No);
Is there a way to get rid of all the calls to QString::fromUtf8()
?
Have you tried using QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"))?
这篇关于将Qt默认编码设置为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!