当前位置: 首页 > news >正文

QT 多语言转换 ts、qm

        QT开发之路 企业级开发系列文章,主要目标快速学习、完善、提升 相关技能 高效完成企业级项目开发 分享在企业中积累的实用技能和经验。

        通过具体的编码过程、代码示例、步骤详解、核心内容和展示的方法解决遇到的实际问题。

 阅读前声明 本系列文章属于付费内容 禁止转载、复制、抄袭 仅限付费读者阅读参考。

QT 多语言转换 ts、qm

1 运行环境

2 命令用法

3 软件界面

4 vs配置

5 .h代码

6 .cpp代码

7 其它

8 en.ts

9 xf.ts

10 zh.ts

11 其它文章


1 运行环境

         VS2017+QT

2 命令用法

lupdate 更新翻译文件        生成 .ts 文件

用法:

lupdate ./ -ts language/QLinguist_en.ts language/QLinguist_zh.ts language/QLinguist_xf.tslanguage/QLinguist_en.ts //language/目录 按照实际需求更改

lrelease 发布更新文件        生成 .qm 文件

用法:

lrelease language/QLinguist_en.ts language/QLinguist_zh.ts language/QLinguist_xf.tslanguage/QLinguist_en.ts // language/ 目录 按照实际需求更改

3 软件界面

4 vs配置

        项目-> 属性->生成事件->生成后事件->输入

lupdate ./ -ts language/QLinguist_en.ts language/QLinguist_zh.ts language/QLinguist_xf.ts
lrelease language/QLinguist_en.ts language/QLinguist_zh.ts language/QLinguist_xf.ts

5 .h代码

#pragma once#include <QtWidgets/QMainWindow>
#include "ui_QLinguist.h"
#include <QTranslator>
#include <QDebug>#pragma execution_character_set("utf-8")
class QLinguist : public QMainWindow
{Q_OBJECTpublic:QLinguist(QWidget *parent = nullptr);~QLinguist();private slots:void on_ActionTriggered();void on_ActionXf_Triggered();void on_ActionEn_Triggered();private:Ui::QLinguistClass ui;QString strFilePath = "";QTranslator zh;QTranslator xf;QTranslator en;
};

6 .cpp代码

#include "QLinguist.h"QLinguist::QLinguist(QWidget *parent): QMainWindow(parent)
{ui.setupUi(this);setWindowTitle("多语言切换Demo CSDN 双子座断点 V1.0 https://blog.csdn.net/qq_37529913?type=blog");strFilePath = "C:/Users/dream/source/repos/QLinguist/QLinguist/language/";zh.load(strFilePath + "QLinguist_zh.qm");xf.load(strFilePath + "QLinguist_xf.qm");en.load(strFilePath + "QLinguist_en.qm");connect(ui.action, SIGNAL(triggered()), SLOT(on_ActionTriggered()));connect(ui.action_2, SIGNAL(triggered()), SLOT(on_ActionXf_Triggered()));connect(ui.action_3, SIGNAL(triggered()), SLOT(on_ActionEn_Triggered()));}QLinguist::~QLinguist()
{}void QLinguist::on_ActionTriggered() 
{qDebug() << ".....";qApp->installTranslator(&zh);ui.retranslateUi(this);
}void QLinguist::on_ActionXf_Triggered()
{qDebug() << ".....";qApp->installTranslator(&xf);ui.retranslateUi(this);
}void QLinguist::on_ActionEn_Triggered()
{qDebug() << ".....";qApp->installTranslator(&en);ui.retranslateUi(this);
}

7 其它

void QLinguist::on_ActionEn_Triggered()
{qDebug() << ".....";//qApp->installTranslator(&en);//ui.retranslateUi(this);//ui.lineEdit->setText(tr("图像路径为空!"));
}

8 en.ts

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context><name>QLinguist</name><message><location filename="../QLinguist.cpp" line="51"/><source>图像路径为空!</source><translation type="unfinished">The image path is empty!</translation></message>
</context>
<context><name>QLinguistClass</name><message><location filename="../QLinguist.ui" line="14"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="227"/><source>多语言切换Demo CSDN 双子座断点 V1.0 https://blog.csdn.net/qq_37529913?type=blog</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="29"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="204"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="231"/><source>图像路径:</source><translation type="unfinished">image path:</translation></message><message><location filename="../QLinguist.ui" line="62"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="205"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="232"/><source>曝光:</source><translation type="unfinished">Exposure:</translation></message><message><location filename="../QLinguist.ui" line="95"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="206"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="233"/><source>增益:</source><translation type="unfinished">gain:</translation></message><message><location filename="../QLinguist.ui" line="128"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="207"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="234"/><source>区域:</source><translation type="unfinished">roi:</translation></message><message><location filename="../QLinguist.ui" line="161"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="208"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="235"/><source>串口:</source><translation type="unfinished">com:</translation></message><message><location filename="../QLinguist.ui" line="236"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="209"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="237"/><source>语言选择</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="246"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="201"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="228"/><source>简体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="251"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="202"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="229"/><source>繁体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="256"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="203"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="230"/><source>English</source><translation type="unfinished"></translation></message><message><location filename="../x64/Debug/uic/ui_QLinguist.h" line="200"/><source>QLinguist</source><translation type="unfinished"></translation></message>
</context>
</TS>

9 xf.ts

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context><name>QLinguist</name><message><location filename="../QLinguist.cpp" line="51"/><source>图像路径为空!</source><translation type="unfinished">圖像路徑為空!</translation></message>
</context>
<context><name>QLinguistClass</name><message><location filename="../QLinguist.ui" line="14"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="227"/><source>多语言切换Demo CSDN 双子座断点 V1.0 https://blog.csdn.net/qq_37529913?type=blog</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="29"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="204"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="231"/><source>图像路径:</source><translation type="unfinished">圖像路徑:</translation></message><message><location filename="../QLinguist.ui" line="62"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="205"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="232"/><source>曝光:</source><translation type="unfinished">曝光:</translation></message><message><location filename="../QLinguist.ui" line="95"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="206"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="233"/><source>增益:</source><translation type="unfinished">增益:</translation></message><message><location filename="../QLinguist.ui" line="128"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="207"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="234"/><source>区域:</source><translation type="unfinished">區域:</translation></message><message><location filename="../QLinguist.ui" line="161"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="208"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="235"/><source>串口:</source><translation type="unfinished">串口:</translation></message><message><location filename="../QLinguist.ui" line="236"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="209"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="237"/><source>语言选择</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="246"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="201"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="228"/><source>简体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="251"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="202"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="229"/><source>繁体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="256"/><location filename="../x64/Debug/uic/ui_QLinguist.h" line="203"/><location filename="../x64/Release/uic/ui_QLinguist.h" line="230"/><source>English</source><translation type="unfinished"></translation></message><message><location filename="../x64/Debug/uic/ui_QLinguist.h" line="200"/><source>QLinguist</source><translation type="unfinished"></translation></message>
</context>
</TS>

10 zh.ts

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context><name>QLinguist</name><message><location filename="../QLinguist.cpp" line="49"/><source>图像路径为空!</source><translation type="unfinished">图像路径为空!</translation></message>
</context>
<context><name>QLinguistClass</name><message><location filename="../QLinguist.ui" line="14"/><source>多语言切换Demo CSDN 双子座断点 V1.0 https://blog.csdn.net/qq_37529913?type=blog</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="29"/><source>图像路径:</source><translation type="unfinished">图像路径:</translation></message><message><location filename="../QLinguist.ui" line="62"/><source>曝光:</source><translation type="unfinished">曝光:</translation></message><message><location filename="../QLinguist.ui" line="95"/><source>增益:</source><translation type="unfinished">增益:</translation></message><message><location filename="../QLinguist.ui" line="128"/><source>区域:</source><translation type="unfinished">区域:</translation></message><message><location filename="../QLinguist.ui" line="161"/><source>串口:</source><translation type="unfinished">串口:</translation></message><message><location filename="../QLinguist.ui" line="236"/><source>语言选择</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="246"/><source>简体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="251"/><source>繁体中文</source><translation type="unfinished"></translation></message><message><location filename="../QLinguist.ui" line="256"/><source>English</source><translation type="unfinished"></translation></message>
</context>
</TS>

11 其它文章

相关文章:

QT 多语言转换 ts、qm

QT开发之路 企业级开发系列文章&#xff0c;主要目标快速学习、完善、提升 相关技能 高效完成企业级项目开发 分享在企业中积累的实用技能和经验。 通过具体的编码过程、代码示例、步骤详解、核心内容和展示的方法解决遇到的实际问题。 阅读前声明 本系列文章属于付费内容 禁止…...

C++学习:类和对象(二)

一、默认成员函数 1. 什么是默认成员函数&#xff1f; 在C中&#xff0c;每个类都有一些特殊的成员函数&#xff0c;如果程序员没有显式地声明&#xff0c;编译器会自动为类生成这些函数&#xff0c;这些函数称为默认成员函数 2. 默认成员函数列表 默认构造函数&#xff08…...

深度学习(五):语音处理领域的创新引擎(5/10)

一、深度学习在语音处理中的崛起 在语音处理领域&#xff0c;传统方法如谱减法、维纳滤波等在处理复杂语音信号时存在诸多局限性。这些方法通常假设噪声是平稳的&#xff0c;但实际噪声往往是非平稳的&#xff0c;导致噪声估计不准确。同时&#xff0c;为了去除噪声&#xff0…...

双曲函数(Hyperbolic functuons)公式

在python等语言里有双曲函数库和反双曲函数库&#xff0c;但是并没有包含所有的双曲函数。以numpy为例子&#xff0c;numpy只提供了sinh、cosh、tanh、arcsinh、arccosh、arctanh六种函数&#xff0c;那么其余的就需要用公式计算了。 转换公式 对于函数库不能直接计算的&#…...

【CSS/SCSS】@layer的介绍及使用方法

目录 基本用法layer 的作用与优点分离样式职责&#xff0c;增强代码可读性和可维护性防止无意的样式冲突精确控制样式的逐层覆盖提高复用性 兼容性实际示例&#xff1a;使用 import 管理加载顺序实际示例&#xff1a;混入与 layer 结合使用 layer 是 CSS 中用于组织和管理样式优…...

我为什么投身于青少年AI编程?——打造生态圈(三)

第五部分 青少年AI编程生态圈 一、生态圈 主要涵盖家庭、社区/中小学、高校高职、主管部门。 1、家庭 我们与社区/中小学一道打造让家长满意的模式。 教得好&#xff1a; 费用少&#xff1a; 家门口&#xff1a; 2、社区/中小学 社区党群服务中心和中小学都有大面积科普…...

出海要深潜,中国手机闯关全球化有了新标杆

经济全球化的大势之下&#xff0c;中国科技企业开拓海外市场已成为一种必然选择。 对于国内手机企业来说&#xff0c;推进全球商业版图扩张&#xff0c;业务潜力巨大&#xff0c;海外市场是今后的关键增长引擎。 当前中国手机厂商在海外市场的发展&#xff0c;有收获也有坎坷…...

百度SEO中的关键词密度与内容优化研究【百度SEO专家】

大家好&#xff0c;我是百度SEO专家&#xff08;林汉文&#xff09;&#xff0c;在百度SEO优化中&#xff0c;关键词密度和关键词内容的优化对提升页面排名至关重要。关键词的合理布局与内容的质量是确保网页在百度搜索结果中脱颖而出的关键因素。下面我们将从关键词密度和关键…...

如何用fastapi集成pdf.js 的viewer.html ,并支持 mjs

fastapi 框架 集成pdf.js 的 viewer.html?file=***,支持跨域,支持.mjs .wasm .pdf 给出完整示例代码 要在 FastAPI 框架中集成 pdf.js 的 viewer.html,并支持跨域访问以及 .mjs、.wasm、.pdf 文件的正确加载,可以按照以下步骤进行。下面提供一个完整的示例,包括项目结构…...

文件相对路径与绝对路径

前言&#xff1a; 在写代码绘制图像的过程中&#xff0c;发现出现cant read input file的异常&#xff0c;而且输出框没有绘制图片&#xff0c;所以寻找解决方案。先贴上之前写的简洁版绘制图像代码 1.BackGround类 import java.awt.image.BufferedImage;public class BackG…...

Linux 重启命令全解析:深入理解与应用指南

Linux 重启命令全解析&#xff1a;深入理解与应用指南 在 Linux 系统中&#xff0c;掌握正确的重启命令是确保系统稳定运行和进行必要维护的关键技能。本文将深入解析 Linux 中常见的重启命令&#xff0c;包括功能、用法、适用场景及注意事项。 一、reboot 命令 功能简介 re…...

【北京迅为】《STM32MP157开发板嵌入式开发指南》-第六十七章 Trusted Firmware-A 移植

iTOP-STM32MP157开发板采用ST推出的双核cortex-A7单核cortex-M4异构处理器&#xff0c;既可用Linux、又可以用于STM32单片机开发。开发板采用核心板底板结构&#xff0c;主频650M、1G内存、8G存储&#xff0c;核心板采用工业级板对板连接器&#xff0c;高可靠&#xff0c;牢固耐…...

`a = a + b` 与 `a += b` 的区别

在 Java 中&#xff0c;a a b 和 a b 都用于将 b 的值加到 a 上&#xff0c;但它们之间存在一些重要的区别&#xff0c;尤其是在类型转换和操作行为方面。 使用 操作符时&#xff0c;Java 会自动进行隐式类型转换&#xff0c;而使用 则不会。这意味着在 a b 的情况下&am…...

mysqld.log文件过大,清理后不改变所属用户

#1024程序员节# 一、背景 突然有一天&#xff0c;我的mysql报磁盘不足了。仔细查看才发现&#xff0c;是磁盘满了。而MySQL的日志文件占用了91个G.如下所示&#xff1a; [roothost-172-16-14-128 mysql]# ls -lrth 总用量 93G -rw-r----- 1 mysql mysql 1.1G 7月 30 2023 m…...

v4.7+版本用户充值在交易统计中计算双倍的问题修复

app/services/statistic/TradeStatisticServices.php 文件中 $whereInRecharge[recharge_type] no_system; $whereInRecharge[recharge_type] system; app/model/user/UserRecharge.php 中 修改此搜索器内容 public function searchRechargeTypeAttr($query, $value){ if…...

[GXYCTF 2019]Ping Ping Ping 题解(多种解题方式)

知识点: 命令执行 linux空格绕过 反引号绕过 变量绕过 base64编码绕过 打开页面提示 "听说php可以执行系统函数&#xff1f;我来康康" 然后输入框内提示输入 bjut.edu.cn 输入之后回显信息,是ping 这个网址的信息 输入127.0.0.1 因为提示是命令…...

MODSI EVI 数据的时间序列拟合一阶谐波模型

目录 简介 函数 ee.Reducer.linearRegression(numX, numY) Arguments: Returns: Reducer ee.Image.cat(var_args) Arguments: Returns: Image hsvToRgb() Arguments: Returns: Image 代码 结果 简介 MODIS/006/MOD13A1数据是由美国国家航空航天局(NASA)的MODIS…...

Java:String类(超详解!)

一.常用方法 &#x1f94f;1.字符串构造 字符串构造有三种方法&#xff1a; &#x1f4cc;注意&#xff1a; 1. String是引用类型&#xff0c;内部并不存储字符串本身 如果String是一个引用那么s1和s3应该指向同一个内容&#xff0c;s1和s2是相等的&#xff0c;应该输出两…...

【日志】力扣13.罗马数字转整数 || 解决泛型单例热加载失败问题

2024.10.28 【力扣刷题】 13. 罗马数字转整数 - 力扣&#xff08;LeetCode&#xff09;https://leetcode.cn/problems/roman-to-integer/description/?envTypestudy-plan-v2&envIdtop-interview-150这题用模拟的思想可以给相应的字母赋值&#xff0c;官方的答案用的是用一…...

Mybatis高级

系列文章目录 高级Mybatis&#xff0c;一些结果映射&#xff0c;引入新的注解 目录 系列文章目录 文章目录 一、结果映射 1.ResultType 2.ResultMap 基础应用&#xff1a; 二、一对一 嵌套结果和嵌套查询 嵌套结果 嵌套查询 区别 三、一对多 四、多对多 五、注解补充 1.一对一…...

vscode里如何用git

打开vs终端执行如下&#xff1a; 1 初始化 Git 仓库&#xff08;如果尚未初始化&#xff09; git init 2 添加文件到 Git 仓库 git add . 3 使用 git commit 命令来提交你的更改。确保在提交时加上一个有用的消息。 git commit -m "备注信息" 4 …...

大话软工笔记—需求分析概述

需求分析&#xff0c;就是要对需求调研收集到的资料信息逐个地进行拆分、研究&#xff0c;从大量的不确定“需求”中确定出哪些需求最终要转换为确定的“功能需求”。 需求分析的作用非常重要&#xff0c;后续设计的依据主要来自于需求分析的成果&#xff0c;包括: 项目的目的…...

【Oracle APEX开发小技巧12】

有如下需求&#xff1a; 有一个问题反馈页面&#xff0c;要实现在apex页面展示能直观看到反馈时间超过7天未处理的数据&#xff0c;方便管理员及时处理反馈。 我的方法&#xff1a;直接将逻辑写在SQL中&#xff0c;这样可以直接在页面展示 完整代码&#xff1a; SELECTSF.FE…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

Spring Boot+Neo4j知识图谱实战:3步搭建智能关系网络!

一、引言 在数据驱动的背景下&#xff0c;知识图谱凭借其高效的信息组织能力&#xff0c;正逐步成为各行业应用的关键技术。本文聚焦 Spring Boot与Neo4j图数据库的技术结合&#xff0c;探讨知识图谱开发的实现细节&#xff0c;帮助读者掌握该技术栈在实际项目中的落地方法。 …...

C# 求圆面积的程序(Program to find area of a circle)

给定半径r&#xff0c;求圆的面积。圆的面积应精确到小数点后5位。 例子&#xff1a; 输入&#xff1a;r 5 输出&#xff1a;78.53982 解释&#xff1a;由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982&#xff0c;因为我们只保留小数点后 5 位数字。 输…...

关键领域软件测试的突围之路:如何破解安全与效率的平衡难题

在数字化浪潮席卷全球的今天&#xff0c;软件系统已成为国家关键领域的核心战斗力。不同于普通商业软件&#xff0c;这些承载着国家安全使命的软件系统面临着前所未有的质量挑战——如何在确保绝对安全的前提下&#xff0c;实现高效测试与快速迭代&#xff1f;这一命题正考验着…...

九天毕昇深度学习平台 | 如何安装库?

pip install 库名 -i https://pypi.tuna.tsinghua.edu.cn/simple --user 举个例子&#xff1a; 报错 ModuleNotFoundError: No module named torch 那么我需要安装 torch pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple --user pip install 库名&#x…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

论文笔记——相干体技术在裂缝预测中的应用研究

目录 相关地震知识补充地震数据的认识地震几何属性 相干体算法定义基本原理第一代相干体技术&#xff1a;基于互相关的相干体技术&#xff08;Correlation&#xff09;第二代相干体技术&#xff1a;基于相似的相干体技术&#xff08;Semblance&#xff09;基于多道相似的相干体…...