Vs 2010+ Qt5 實現語言國際化
創建一個工程,cpp代碼如下:
1、創建工程
#include ""
#include <QFileDialog>
#include <QMessageBox>
LanguageInternationalized::LanguageInternationalized(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi();
QMenuBar *menuBar = QMenuBar();
QMenu *fileMenu = QMenu(tr(""), menuBar);
QAction *newFile = QAction(tr(""), fileMenu);
fileMenu->addAction(newFile);
QAction *openFile = QAction(tr(""), fileMenu);
fileMenu->addAction(openFile);
menuBar->addMenu(fileMenu);
setMenuBar(menuBar);
}
LanguageInternationalized::~LanguageInternationalized()
{
}
2、右鍵工程,創建ts文件
#include <QtWidgets/QApplication>
#include <QTranslator>
main( argc, *argv[])
{
QApplication a(argc, argv);
QTranslator qtTranslator;
qtTranslator.load("");
a.installTranslator(&qtTranslator);
LanguageInternationalized w;
w.show();
a.exec();
}
7、運行程序,就能看到效果了