Qt中带有QString的阿拉伯语 [英] Arabic in Qt with QString

查看:134
本文介绍了Qt中带有QString的阿拉伯语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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(在VM中)/UTF-8源文件:

Qt Creator 2.7/Windows 7 (in a VM)/UTF-8 source file:

这篇关于Qt中带有QString的阿拉伯语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆