问题
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));
回答1:
If by direct you mean using a Unicode code point value, then QChar may be it:
QString s = QChar(0x4FF0);
回答2:
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");
回答3:
As a direct pointer, try QString(QChar(0x4FF0));
You need to ensure you have the correct utf-16 encoding.
来源:https://stackoverflow.com/questions/7586860/how-to-specify-a-unicode-character-using-qstring