Qt转换unicode实体 [英] Qt convert unicode entities

查看:266
本文介绍了Qt转换unicode实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在QT 5.4和C ++中,我尝试解码具有unicode实体的字符串。

In QT 5.4 and C++ I try to decode a string that has unicode entities.

我有这个QString:

I have this QString:

QString string = "file\u00d6\u00c7\u015e\u0130\u011e\u00dc\u0130\u00e7\u00f6\u015fi\u011f\u00fc\u0131.txt";

我想将此字符串转换为:fileÖÇŞİĞÜİçöşiğüı.txt

I want to convert this string to this: fileÖÇŞİĞÜİçöşiğüı.txt

我尝试了 QString toUtf8 fromUtf8 方法。

有没有办法使用Qt转换?

Is there a way to convert it by using Qt?

推荐答案

Qt提供了一个名为 QStringLiteral 的宏来处理字符串字面量正确。

Qt provides a macro called QStringLiteral for handling string literals correctly.

这是一个完整的工作示例:

Here's a full working example:

#include <QString>
#include <QDebug>

int main(void) {
   QString string = QStringLiteral("file\u00d6\u00c7\u015e\u0130\u011e\u00dc\u0130\u00e7\u00f6\u015fi\u011f\u00fc\u0131.txt");
   qDebug() << string;

   return 0;
}

如上所述,您需要打印到控制台支持这些字符以使其工作。

As mentioned in the above comments, you do need to print to a console that supports these characters for this to work.

这篇关于Qt转换unicode实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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