将 Qt 默认编码设置为 UTF-8 [英] Set Qt default encoding to UTF-8
本文介绍了将 Qt 默认编码设置为 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 Qt 应用程序中,我的源代码文件被编码为 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);
...当我显示那个消息框时,字符š"不会显示为š",而是一些奇怪的东西.这是因为 Qt 将所有 C 字符串转换为使用 LATIN-1 编码的字符串.为了解决这个问题,我一直在使用:
...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);
有没有办法摆脱对QString::fromUtf8()
的所有调用?
Is there a way to get rid of all the calls to QString::fromUtf8()
?
推荐答案
您是否尝试过使用 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"))?
这篇关于将 Qt 默认编码设置为 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文