Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在Qt中使用unicode?_C++_Qt_Unicode_Encoding_Qt4 - Fatal编程技术网

C++ 如何在Qt中使用unicode?

C++ 如何在Qt中使用unicode?,c++,qt,unicode,encoding,qt4,C++,Qt,Unicode,Encoding,Qt4,我想在QLineEdit字段中使用放大镜Unicode符号。 我知道如何使用QChar使用16位unicode符号,但是我不知道如何使用由5个十六进制数字表示的unicode符号 QLineEdit edit = new QLineEdit(); edit.setFont(QFont("Segoe UI Symbol")); edit.setText(????); 到目前为止,我已经尝试: edit.setText(QString::fromUtf8("\U0001F50E")); 这给了编

我想在QLineEdit字段中使用放大镜Unicode符号。 我知道如何使用QChar使用16位unicode符号,但是我不知道如何使用由5个十六进制数字表示的unicode符号

QLineEdit edit = new QLineEdit();
edit.setFont(QFont("Segoe UI Symbol"));
edit.setText(????);
到目前为止,我已经尝试:

edit.setText(QString::fromUtf8("\U0001F50E"));
这给了编译器警告:

warning C4566: character represented by universal-character-name '\UD83DDD0E' cannot be represented in the current code page
warning C4566: character represented by universal-character-name '\UD83DDD0E' cannot be represented in the current code page (1252)
结果是:

我还尝试:

edit.setText(QString("\U0001F50E"));
这给了编译器警告:

warning C4566: character represented by universal-character-name '\UD83DDD0E' cannot be represented in the current code page
warning C4566: character represented by universal-character-name '\UD83DDD0E' cannot be represented in the current code page (1252)
并给出:


我尝试了所有你可以尝试的QChar。我还试着切换我的CPP文件的编码,复制并粘贴符号,但没有成功

您已经知道答案-将其指定为正确的UTF-16字符串

U+FFFF以上的Unicode代码点在UTF-16中使用代理项对表示,代理项对是两个16位代码单元,共同作用以表示完整的Unicode代码点值。对于U+1F50E,代理项对为U+D83D U+DD0E

在Qt中,UTF-16编码单元表示为QChar,因此需要两个QChar值,例如:

edit.setText(QString::fromWCharArray(L"\xD83D\xDD0E"));
或:

假设平台的sizeofwchar\u t为2而不是4

在您的示例中,您尝试使用QString::fromUtf8,但给出了一个无效的UTF-8字符串。对于U+1F50E,它应该是这样的:

edit.setText(QString::fromUtf8("\xF0\x9F\x94\x8E"));
您也可以改用QString::fromUcs4:


^这是一个类似的问题,但答案真的对我毫无帮助,因为您使用的是字符串文字,您是否尝试过使用?