开发者

How to specify a unicode character using QString?

How can I specify a unicode character by code (such as "4FF0") using QString? I tried QString s("\u4FF0"); but it only outputs a question mark. Any idea how to do this?

Edit:

It works that way, but is there a 开发者_如何学编程more direct way?

std::wstring str = L"\u4FF07";
QString s = QString::fromStdWString(str));


If by direct you mean using a Unicode code point value, then QChar may be it:

QString s = QChar(0x4FF0);


Apparently '\u' only works with UTF-8:

QString s = QString::fromUtf8("\u4FF0");

// Or with that at the start of your main function:
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
...
QString s("\u4FF0");


Since C++11 you can use UTF-8 string literal prefix (u8):

QString s(u8"\u4FF0");


As a direct pointer, try QString(QChar(0x4FF0));

You need to ensure you have the correct utf-16 encoding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜