QTextEdit unicode QString 不工作

QTextEdit unicode QString not working

我正在尝试使用自定义字体(Veteran Typewriter)编写在 QTextEdit 中打印消息的方法。我使用的这种字体支持 Unicode,但是当我在我的应用程序中使用它时,所有字符如“±”、“Ç”、“ż”和其他波兰语字符都无法正确显示(全部被替换为�)。你知道为什么吗?如何强制使用Unicode? (我在 Windows 10 x64 上使用 Visual Studio 2013 Community + Qt5 Add-on,项目也被定义为 x64。

我的代码:

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

这就是我发送示例消息的方式:

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

如果你打算在 Qt 中使用 Unicode 字符串文字,你应该使用 QStringLiteral 宏。

换句话说,您的代码将如下所示:

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