Important: Please read the Qt Code of Conduct -

Qml can not show string encoded by utf-8?

  • 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.

  • @Crawl-W I think you should use the unicode notation \u2103 (works for me ™)

    Text {
        text: "\u2103"
        font.pixelSize: 24

  • 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
        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?

  • @KroMignon Yes, it works! I use \u2103 for Celsius, which is utf-16 encoding.

  • @fcarney Yes, My test and @KroMignon 's demo also tends to uft-16.

Log in to reply