带有 QString 的 Qt 中的阿拉伯语 [英] Arabic in Qt with QString
本文介绍了带有 QString 的 Qt 中的阿拉伯语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 Qt 应用程序中添加一个阿拉伯语标题,但没有成功.这是我的代码:
I want to add an Arabic title to my Qt application, but it didn't work. Here is my code:
#include "mainwindow.h"
#include <QtGui/QApplication>
#include <QString>
#include <QTextStream>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
mainWindow w;
QString appTitle("تجربه");
w.setWindowTitle(appTitle);
w.show();
return a.exec();
}
这是输出:
我该如何纠正?
推荐答案
这看起来像是一个典型的UTF-8 解释为 ISO-8859-1"编码问题. 事实上它是一个CP1256解释为Latin1"问题.
That looks like a typical "UTF-8 interpreted as ISO-8859-1" encoding issue. In fact it's a "CP1256 interpreted as Latin1" issue.
在 Windows 上,使用非 Unicode 代码页,请尝试以下操作:
On Windows, with a non-Unicode codepage, try the following:
QString appTitle = QString::fromLocal8Bit("تجربه");
如果你的源文件是 UTF-8,试试这个:
If you had your source file in UTF-8, try this instead:
QString appTitle = QString::fromUtf8("تجربه");
(参见 codecForLocale()
应该做什么.)
(See codecForLocale()
for what that's supposed to do.)
Qt Creator 2.7/Windows 7(在虚拟机中)/UTF-8 源文件:
Qt Creator 2.7/Windows 7 (in a VM)/UTF-8 source file:
这篇关于带有 QString 的 Qt 中的阿拉伯语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文