Retrieve Unicode code points > U+FFFF from QChar

前端 未结 3 1708
失恋的感觉
失恋的感觉 2021-01-12 11:49

I have an application that is supposed to deal with all kinds of characters and at some point display information about them. I use Qt and its inherent Unicode support in QC

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 12:26

    The solution appears to lay in code that is documented but not seen much on the Web. You can get the utf-8 value in decimal form. You then apply to determine if a single QChar is large enough. In this case it is not. Then you need to create two QChar's.

    uint32_t cp = 155222; // a 4-byte Japanese character 
    QString str;
    if(Qchar::requiresSurrogate(cp))
    {
        QChar charArray[2];
        charArray[0] = QChar::highSurrogate(cp);
        charArray[1] = QChar::lowSurrogate(cp);
        str =  QString(charArray, 2);
    }
    

    The resulting QString will contain the correct information to display your supplemental utf-8 character.

提交回复
热议问题