当前位置:网站首页>QT dynamic translation of Chinese and English languages
QT dynamic translation of Chinese and English languages
2022-04-23 03:20:00 【Happinessคิดถึง】
**
Update time :2021-04-21
**
The interface program is suitable for users in many countries , There will be a choice of language .
design sketch :

The translation is divided into several parts :
1. First determine the position of the string you want to translate
2. stay pro Add... To the document :TRANSLATIONS = chinese.ts
Open the compiler you are using cmd, Switch to project path . And implement :lupdate.exe xxx.pro obtain ts file

3. Use linguist.exe Open generated ts file , And add the Chinese you want to translate .
4. After translation , choice – file – Also published as – Save to local qm File can .

Code using :
The header file :
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QTranslator> // internationalization
#include <QLibraryInfo> // internationalization
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_comboBox_currentIndexChanged(int index);
private:
Ui::Widget *ui;
QTranslator tran;
};
#endif // WIDGET_H
cpp file :
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
// Load translation qm file
void Widget::on_comboBox_currentIndexChanged(int index)
{
if(ui->comboBox->currentIndex()==1)
{
tran.load(":/lang/chinese.qm");
qApp->installTranslator(&tran);
}else
{
qApp->removeTranslator(&tran);
}
ui->retranslateUi(this);
}
Here I just translate and use . There are lots of holes in it . I'll update it later .
I've only done Chinese and English translation here . If there are other languages that need corresponding qm File for translation . Here still suggest that you should learn English well . Purring .
版权声明
本文为[Happinessคิดถึง]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220623156500.html
边栏推荐
- OLED多级菜单记录
- 你真的懂hashCode和equals吗???
- Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions
- Flink real-time data warehouse project - Design and implementation of DWS layer
- 2022a special equipment related management (elevator) work license question bank and simulation examination
- ThreadLocal 测试多线程变量实例
- Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
- Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
- Comprehensive calculation of employee information
- Detailed explanation of socket programming send() and recv() functions
猜你喜欢

搭建XAMPP时mysql端口被占用

可以接收多种数据类型参数——可变参数
![[MySQL] left function | right function](/img/26/82e0f2280de011636c26931a74e749.png)
[MySQL] left function | right function

手机连接电脑后,QT的QDIR怎么读取手机文件路径

IDEA查看历史记录【文件历史和项目历史】

MySQL port is occupied when building xampp

Configuration table and page information automatically generate curd operation page

OLED多级菜单记录

MySQL keyword group_ Concat, combined connection query

OLED multi-level menu record
随机推荐
EasyUI's combobox implements three-level query
超好用的Excel异步导出功能
你真的懂hashCode和equals吗???
. net core current limiting control - aspnetcoreratelimit
Test experience data
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
Ide-idea-problem
Supersocket is Use in net5 - startup
Idempotency practice operation, explaining idempotency based on business
JS inheritance
Supersocket is Used in net5 - command
月薪10k-20k都无法回答的事务问题,你会吗?
MySQL之explain关键字详解
xutils3修改了我提报的一个bug,开心
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
软件测试相关知识~
The most easy to understand service container and scope of dependency injection
2022年P气瓶充装培训试题及模拟考试
Idea view history [file history and project history]
MySQL installation pit