zoukankan      html  css  js  c++  java
  • QML 中文支持

    有三种方式:

    1,国际化

    2:写uincode吗

    3:直接写文字再QML文件中,和symbian一样,文件保存成utf8

    • 使用 Qt 的国际化功能(与QtScript完全一样,使用 qsTr())

    • 使用 unicode 的转义字符("\uxxxx")

    #include <QtCore/QTranslator>
    #include <QtGui/QApplication>
    #include <QtDeclarative/QDeclarativeView>

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QTranslator translator;
        translator.load("first_zh_CN.qm", "i18n");
        app.installTranslator(&translator);
        QDeclarativeView view;
        view.setSource(QUrl::fromLocalFile("first.qml"));
        view.show();
        return app.exec();
    }

    first.qml

    • 待翻译字符串 qsTr("text")
    • "我是中文"的unicode表示 "\u6211\u662f\u4e2d\u6587"

    Rectangle {
        id: page
        100
        height: 100
        color: "red"
        Text {
            id: s1
            x: 35
            y: 15
            text: qsTr("text")
        }
        Text {
            id: s2
            x: 35
            y: 63
            text: "\u6211\u662f\u4e2d\u6587"
        }
    }

    提取或更新待翻译字符串

    lupdate first.qml -ts i18n/first_zh_CN.ts
    调用 linguist 翻译文本,并发布 first_zh_CN.qm 文件

  • 相关阅读:
    Intellij IDEA使用姿势
    款阿里开源的 Java 诊断工具Arthas
    Spring Boot Runner启动器
    Spring Boot 2.x 启动全过程源码分析
    Spring Boot自动配置原理
    vue包部署在tomcat上,解决资源路径问题
    输入回车 回显换行
    session和cookie
    WebStorage——SessionStorage、LocalStorage与cookie
    HTML5 cache
  • 原文地址:https://www.cnblogs.com/cute/p/2383399.html
Copyright © 2011-2022 走看看