当前位置: 首页 > 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.一对一…...

椭圆曲线密码学(ECC)

一、ECC算法概述 椭圆曲线密码学&#xff08;Elliptic Curve Cryptography&#xff09;是基于椭圆曲线数学理论的公钥密码系统&#xff0c;由Neal Koblitz和Victor Miller在1985年独立提出。相比RSA&#xff0c;ECC在相同安全强度下密钥更短&#xff08;256位ECC ≈ 3072位RSA…...

系统设计 --- MongoDB亿级数据查询优化策略

系统设计 --- MongoDB亿级数据查询分表策略 背景Solution --- 分表 背景 使用audit log实现Audi Trail功能 Audit Trail范围: 六个月数据量: 每秒5-7条audi log&#xff0c;共计7千万 – 1亿条数据需要实现全文检索按照时间倒序因为license问题&#xff0c;不能使用ELK只能使用…...

渲染学进阶内容——模型

最近在写模组的时候发现渲染器里面离不开模型的定义,在渲染的第二篇文章中简单的讲解了一下关于模型部分的内容,其实不管是方块还是方块实体,都离不开模型的内容 🧱 一、CubeListBuilder 功能解析 CubeListBuilder 是 Minecraft Java 版模型系统的核心构建器,用于动态创…...

《基于Apache Flink的流处理》笔记

思维导图 1-3 章 4-7章 8-11 章 参考资料 源码&#xff1a; https://github.com/streaming-with-flink 博客 https://flink.apache.org/bloghttps://www.ververica.com/blog 聚会及会议 https://flink-forward.orghttps://www.meetup.com/topics/apache-flink https://n…...

CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

【学习笔记】深入理解Java虚拟机学习笔记——第4章 虚拟机性能监控,故障处理工具

第2章 虚拟机性能监控&#xff0c;故障处理工具 4.1 概述 略 4.2 基础故障处理工具 4.2.1 jps:虚拟机进程状况工具 命令&#xff1a;jps [options] [hostid] 功能&#xff1a;本地虚拟机进程显示进程ID&#xff08;与ps相同&#xff09;&#xff0c;可同时显示主类&#x…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

Go 语言并发编程基础:无缓冲与有缓冲通道

在上一章节中&#xff0c;我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道&#xff0c;它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好&#xff0…...

LabVIEW双光子成像系统技术

双光子成像技术的核心特性 双光子成像通过双低能量光子协同激发机制&#xff0c;展现出显著的技术优势&#xff1a; 深层组织穿透能力&#xff1a;适用于活体组织深度成像 高分辨率观测性能&#xff1a;满足微观结构的精细研究需求 低光毒性特点&#xff1a;减少对样本的损伤…...