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开发之路 企业级开发系列文章,主要目标快速学习、完善、提升 相关技能 高效完成企业级项目开发 分享在企业中积累的实用技能和经验。 通过具体的编码过程、代码示例、步骤详解、核心内容和展示的方法解决遇到的实际问题。 阅读前声明 本系列文章属于付费内容 禁止…...
C++学习:类和对象(二)
一、默认成员函数 1. 什么是默认成员函数? 在C中,每个类都有一些特殊的成员函数,如果程序员没有显式地声明,编译器会自动为类生成这些函数,这些函数称为默认成员函数 2. 默认成员函数列表 默认构造函数(…...
深度学习(五):语音处理领域的创新引擎(5/10)
一、深度学习在语音处理中的崛起 在语音处理领域,传统方法如谱减法、维纳滤波等在处理复杂语音信号时存在诸多局限性。这些方法通常假设噪声是平稳的,但实际噪声往往是非平稳的,导致噪声估计不准确。同时,为了去除噪声࿰…...
双曲函数(Hyperbolic functuons)公式
在python等语言里有双曲函数库和反双曲函数库,但是并没有包含所有的双曲函数。以numpy为例子,numpy只提供了sinh、cosh、tanh、arcsinh、arccosh、arctanh六种函数,那么其余的就需要用公式计算了。 转换公式 对于函数库不能直接计算的&#…...
【CSS/SCSS】@layer的介绍及使用方法
目录 基本用法layer 的作用与优点分离样式职责,增强代码可读性和可维护性防止无意的样式冲突精确控制样式的逐层覆盖提高复用性 兼容性实际示例:使用 import 管理加载顺序实际示例:混入与 layer 结合使用 layer 是 CSS 中用于组织和管理样式优…...
我为什么投身于青少年AI编程?——打造生态圈(三)
第五部分 青少年AI编程生态圈 一、生态圈 主要涵盖家庭、社区/中小学、高校高职、主管部门。 1、家庭 我们与社区/中小学一道打造让家长满意的模式。 教得好: 费用少: 家门口: 2、社区/中小学 社区党群服务中心和中小学都有大面积科普…...
出海要深潜,中国手机闯关全球化有了新标杆
经济全球化的大势之下,中国科技企业开拓海外市场已成为一种必然选择。 对于国内手机企业来说,推进全球商业版图扩张,业务潜力巨大,海外市场是今后的关键增长引擎。 当前中国手机厂商在海外市场的发展,有收获也有坎坷…...
百度SEO中的关键词密度与内容优化研究【百度SEO专家】
大家好,我是百度SEO专家(林汉文),在百度SEO优化中,关键词密度和关键词内容的优化对提升页面排名至关重要。关键词的合理布局与内容的质量是确保网页在百度搜索结果中脱颖而出的关键因素。下面我们将从关键词密度和关键…...
如何用fastapi集成pdf.js 的viewer.html ,并支持 mjs
fastapi 框架 集成pdf.js 的 viewer.html?file=***,支持跨域,支持.mjs .wasm .pdf 给出完整示例代码 要在 FastAPI 框架中集成 pdf.js 的 viewer.html,并支持跨域访问以及 .mjs、.wasm、.pdf 文件的正确加载,可以按照以下步骤进行。下面提供一个完整的示例,包括项目结构…...
文件相对路径与绝对路径
前言: 在写代码绘制图像的过程中,发现出现cant read input file的异常,而且输出框没有绘制图片,所以寻找解决方案。先贴上之前写的简洁版绘制图像代码 1.BackGround类 import java.awt.image.BufferedImage;public class BackG…...
Linux 重启命令全解析:深入理解与应用指南
Linux 重启命令全解析:深入理解与应用指南 在 Linux 系统中,掌握正确的重启命令是确保系统稳定运行和进行必要维护的关键技能。本文将深入解析 Linux 中常见的重启命令,包括功能、用法、适用场景及注意事项。 一、reboot 命令 功能简介 re…...
【北京迅为】《STM32MP157开发板嵌入式开发指南》-第六十七章 Trusted Firmware-A 移植
iTOP-STM32MP157开发板采用ST推出的双核cortex-A7单核cortex-M4异构处理器,既可用Linux、又可以用于STM32单片机开发。开发板采用核心板底板结构,主频650M、1G内存、8G存储,核心板采用工业级板对板连接器,高可靠,牢固耐…...
`a = a + b` 与 `a += b` 的区别
在 Java 中,a a b 和 a b 都用于将 b 的值加到 a 上,但它们之间存在一些重要的区别,尤其是在类型转换和操作行为方面。 使用 操作符时,Java 会自动进行隐式类型转换,而使用 则不会。这意味着在 a b 的情况下&am…...
mysqld.log文件过大,清理后不改变所属用户
#1024程序员节# 一、背景 突然有一天,我的mysql报磁盘不足了。仔细查看才发现,是磁盘满了。而MySQL的日志文件占用了91个G.如下所示: [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可以执行系统函数?我来康康" 然后输入框内提示输入 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类(超详解!)
一.常用方法 🥏1.字符串构造 字符串构造有三种方法: 📌注意: 1. String是引用类型,内部并不存储字符串本身 如果String是一个引用那么s1和s3应该指向同一个内容,s1和s2是相等的,应该输出两…...
【日志】力扣13.罗马数字转整数 || 解决泛型单例热加载失败问题
2024.10.28 【力扣刷题】 13. 罗马数字转整数 - 力扣(LeetCode)https://leetcode.cn/problems/roman-to-integer/description/?envTypestudy-plan-v2&envIdtop-interview-150这题用模拟的思想可以给相应的字母赋值,官方的答案用的是用一…...
Mybatis高级
系列文章目录 高级Mybatis,一些结果映射,引入新的注解 目录 系列文章目录 文章目录 一、结果映射 1.ResultType 2.ResultMap 基础应用: 二、一对一 嵌套结果和嵌套查询 嵌套结果 嵌套查询 区别 三、一对多 四、多对多 五、注解补充 1.一对一…...
AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南
点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...
Docker 运行 Kafka 带 SASL 认证教程
Docker 运行 Kafka 带 SASL 认证教程 Docker 运行 Kafka 带 SASL 认证教程一、说明二、环境准备三、编写 Docker Compose 和 jaas文件docker-compose.yml代码说明:server_jaas.conf 四、启动服务五、验证服务六、连接kafka服务七、总结 Docker 运行 Kafka 带 SASL 认…...
高频面试之3Zookeeper
高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个?3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制(过半机制࿰…...
linux 错误码总结
1,错误码的概念与作用 在Linux系统中,错误码是系统调用或库函数在执行失败时返回的特定数值,用于指示具体的错误类型。这些错误码通过全局变量errno来存储和传递,errno由操作系统维护,保存最近一次发生的错误信息。值得注意的是,errno的值在每次系统调用或函数调用失败时…...
学习STC51单片机31(芯片为STC89C52RCRC)OLED显示屏1
每日一言 生活的美好,总是藏在那些你咬牙坚持的日子里。 硬件:OLED 以后要用到OLED的时候找到这个文件 OLED的设备地址 SSD1306"SSD" 是品牌缩写,"1306" 是产品编号。 驱动 OLED 屏幕的 IIC 总线数据传输格式 示意图 …...
BCS 2025|百度副总裁陈洋:智能体在安全领域的应用实践
6月5日,2025全球数字经济大会数字安全主论坛暨北京网络安全大会在国家会议中心隆重开幕。百度副总裁陈洋受邀出席,并作《智能体在安全领域的应用实践》主题演讲,分享了在智能体在安全领域的突破性实践。他指出,百度通过将安全能力…...
Redis数据倾斜问题解决
Redis 数据倾斜问题解析与解决方案 什么是 Redis 数据倾斜 Redis 数据倾斜指的是在 Redis 集群中,部分节点存储的数据量或访问量远高于其他节点,导致这些节点负载过高,影响整体性能。 数据倾斜的主要表现 部分节点内存使用率远高于其他节…...
【分享】推荐一些办公小工具
1、PDF 在线转换 https://smallpdf.com/cn/pdf-tools 推荐理由:大部分的转换软件需要收费,要么功能不齐全,而开会员又用不了几次浪费钱,借用别人的又不安全。 这个网站它不需要登录或下载安装。而且提供的免费功能就能满足日常…...
AirSim/Cosys-AirSim 游戏开发(四)外部固定位置监控相机
这个博客介绍了如何通过 settings.json 文件添加一个无人机外的 固定位置监控相机,因为在使用过程中发现 Airsim 对外部监控相机的描述模糊,而 Cosys-Airsim 在官方文档中没有提供外部监控相机设置,最后在源码示例中找到了,所以感…...
【JVM面试篇】高频八股汇总——类加载和类加载器
目录 1. 讲一下类加载过程? 2. Java创建对象的过程? 3. 对象的生命周期? 4. 类加载器有哪些? 5. 双亲委派模型的作用(好处)? 6. 讲一下类的加载和双亲委派原则? 7. 双亲委派模…...
