Qml can not show string encoded by utf-8?
-
wrote on 19 Nov 2020, 05:51 last edited by
Text { text: "\xE2\x84\x83" font.pixelSize: 24 }
"\xE2\x84\x83"
is the UTF-8 encoding for Celsius. It shows as gabberish characters in qml, normal in c++.
My platform is Windows 10, MSVC2019 with Qt 5.15.0 64bit. -
Text { text: "\xE2\x84\x83" font.pixelSize: 24 }
"\xE2\x84\x83"
is the UTF-8 encoding for Celsius. It shows as gabberish characters in qml, normal in c++.
My platform is Windows 10, MSVC2019 with Qt 5.15.0 64bit.wrote on 19 Nov 2020, 07:17 last edited by KroMignon@Crawl-W I think you should use the unicode notation
\u2103
(works for me ™)Text { text: "\u2103" font.pixelSize: 24 }
-
wrote on 19 Nov 2020, 20:07 last edited by
I cannot remember everything I was doing in this code. But I was trying to do conversions. Here are some of the ways I was testing things. I thought text in QML was UTF-16, but I could be wrong on that:
// from utf32 to utf16 // https://unicodebook.readthedocs.io/unicode_encodings.html#surrogates function surrogate(input){ var output if(input < 0x10000 || input > 0x10FFFF){ return output } var code = input - 0x10000 var low = 0xD800 | (code >> 10) var high = 0xDC00 | (code & 0x3FF) output = String.fromCharCode(low) + String.fromCharCode(high) return output } title: qsTr("Font Testing 💩 😀 %1 %2 %3").arg(surrogate(0x1F4A9)).arg("\u{1F4A9}").arg(String.fromCodePoint(0x1F4A9))
Is text UTF8 or UTF16 in QML?
-
@Crawl-W I think you should use the unicode notation
\u2103
(works for me ™)Text { text: "\u2103" font.pixelSize: 24 }
wrote on 8 Dec 2020, 02:51 last edited by@KroMignon Yes, it works! I use
\u2103
for Celsius, which is utf-16 encoding. -
I cannot remember everything I was doing in this code. But I was trying to do conversions. Here are some of the ways I was testing things. I thought text in QML was UTF-16, but I could be wrong on that:
// from utf32 to utf16 // https://unicodebook.readthedocs.io/unicode_encodings.html#surrogates function surrogate(input){ var output if(input < 0x10000 || input > 0x10FFFF){ return output } var code = input - 0x10000 var low = 0xD800 | (code >> 10) var high = 0xDC00 | (code & 0x3FF) output = String.fromCharCode(low) + String.fromCharCode(high) return output } title: qsTr("Font Testing 💩 😀 %1 %2 %3").arg(surrogate(0x1F4A9)).arg("\u{1F4A9}").arg(String.fromCodePoint(0x1F4A9))
Is text UTF8 or UTF16 in QML?
wrote on 8 Dec 2020, 02:57 last edited by@fcarney Yes, My test and @KroMignon 's demo also tends to uft-16.