一 Qt Widgets Application类型工程
1. 创建Qt Widgets Application工程hello_i18n
2. 编辑pro工程文件,新增代码 TRANSLATIONS=hellotr_zh.ts ,新增hello_i18n.qrc资源文件,如下:
#-------------------------------------------------
#
# Project created by QtCreator 2016-06-20T12:05:20
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = hello_i18n
TEMPLATE = app
INCLUDEPATH += .
SOURCES += main.cpp
HEADERS +=
TRANSLATIONS = hellotr_zh.ts
CONFIG += mobility
MOBILITY =
DISTFILES +=
RESOURCES += \
hello_i18n.qrc
3.编辑main.cpp文件,如下:
#include <QApplication>
#include <QDebug>
#include <QTextCodec>
#include <QPushButton>
#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator translator;
bool