Search code examples
windowsqtunicodeqtextedit

QTextEdit unicode QString not working


I'm trying to write method which prints messages in QTextEdit, using custom font (Veteran Typewriter). This font which I use supports Unicode but when I use it in my application, all characters like 'ą', 'ę', 'ż' and other polish characters are not shows correctly (all are replaced by �). Do you have any idea why? How to force use Unicode? (I'm using Visual Studio 2013 Community + Qt5 Add-on, on Windows 10 x64 and project is defined as x64 too).

My code:

void QtCubic::QtCStartScreen::sendMessage(QString message) {
    if (log.toPlainText().length() != 0) {
        log.insertPlainText("\n");
    }
    log.insertPlainText(message);
}

And this is how I send example meassage:

splashScreen.sendMessage("Zażółć gęślą jaźń");

Solution

  • If you're going to use Unicode string literals in Qt, you should be using the QStringLiteral macro.

    In other words, your code would look like this:

    splashScreen.sendMessage(QStringLiteral("Zażółć gęślą jaźń"));