Home > Back-end >  QT QString to qml string converts with question marks on windows
QT QString to qml string converts with question marks on windows

Time:10-07

When I am trying to display text that contains "·" symbol in QML, I am facing a strange behavoiur.

If I define the string with this symbol directly in the qml file:

...
Text {
    text: "1 · 2"
}

Everything displays fine, but when I am trying to get this string from c :

...
Q_INVOKABLE QString brokenStr() {
    return QString("1 · 2");
}

...
Text {
    text: myQObjectClass.brokenStr()
}

The "·" symbol is displayed like a question mark, and this happens only on Windows. On macOS and linux it displays correctly.enter image description here

Looks like something going wrong when QString converts to a qml string. Any ideas how to solve this?

CodePudding user response:

As Öö Tiib mentioned, compiler on windows could not read the plain "·" correctly. The workaround was to use QChar(0xb7) instead.

Final solution is returning QString("1 %1 2").arg(QChar(0xb7)) from cpp function

  • Related