c++ - How do you use unicode in Qt? -
this question has answer here:
i use magnifying glass (u+1f50e) unicode symbol in qlineedit field. figured out how use 16-bit unicode symbols using qchar have no idea how use unicode symbol represented 5 hex digits.
qlineedit edit = new qlineedit(); edit.setfont(qfont("segoe ui symbol")); edit.settext(????); so far have tried:
edit.settext(qstring::fromutf8("\u0001f50e")); which gave compiler warning:
warning c4566: character represented universal-character-name '\ud83ddd0e' cannot represented in current code page and showed as: ??
i tried:
edit.settext(qstring("\u0001f50e")); which gave compiler warning:
warning c4566: character represented universal-character-name '\ud83ddd0e' cannot represented in current code page (1252) and gave: ??
i tried try qchar. tried switching encoding of cpp file , copying , pasting symbol in, didn't work.
you know answer - specify proper utf-16 string.
unicode codepoints above u+ffff represented in utf-16 using surrogate pair, 2 16bit codeunits acting represent full unicode codepoint value. u+1f50e, surrogate pair u+d83d u+dd0e.
in qt, utf-16 codeunit represented qchar, need 2 qchar values, eg:
edit.settext(qstring::fromwchararray(l"\xd83d\xdd0e")); or:
edit.settext(qstring::fromstdwstring(l"\xd83d\xdd0e")); assuming platform sizeof(wchar_t) 2 , not 4.
in example, tried using qstring::fromutf8(), gave invalid utf-8 string. u+1f50e, should have looked instead:
edit.settext(qstring::fromutf8("\xf0\x9f\x94\x8e")); you can use qstring::fromucs4() instead:
uint cp = 0x1f50e; edit.settext(qstring::fromucs4(&cp, 1));
Comments
Post a Comment