Qt学习之路: 国际化(上)
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QMenuBar *menuBar = new QMenuBar(this);
QMenu *fileMenu = new QMenu(tr("&File"), menuBar);
QAction *newFile = new QAction(tr("&New..."), fileMenu);
fileMenu->addAction(newFile);
QAction *openFile = new QAction(tr("&Open..."), fileMenu);
fileMenu->addAction(openFile);
menuBar->addMenu(fileMenu);
setMenuBar(menuBar);
connect(openFile, SIGNAL(triggered()), this, SLOT(fileOpen()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::fileOpen()
{
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setWindowTitle(tr("Open File"));
fileDialog->setDirectory(".");
if(fileDialog->exec() == QDialog::Accepted) {
QString path = fileDialog->selectedFiles()[0];
QMessageBox::information(NULL, tr("Path"), tr("You selected\n%1").arg(path));
} else {
QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
}
}

TRANSLATIONS += myapp.ts
lupdate MyApp.pro

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator qtTranslator;
qtTranslator.load("myapp.qm");
a.installTranslator(&qtTranslator);
MainWindow w;
w.resize(800, 600);
w.show();
return a.exec();
}
Qt学习之路: 国际化(上)的更多相关文章
- QT学习之路--创建一个对话框
Q_OBJECT:这是一个宏,凡是定义信号槽的类都必须声明这个宏. 函数tr()全名是QObject::tr(),被他处理过的字符串可以使用工具提取出来翻译成其他语言,也就是做国际化使用. 对于QT学 ...
- Qt 学习之路 2(10):对象模型
Home / Qt 学习之路 2 / Qt 学习之路 2(10):对象模型 Qt 学习之路 2(10):对象模型 豆子 2012年9月2日 Qt 学习之路 2 45条评论 标准 C++ 对象模 ...
- Qt 学习之路 2(9):资源文件
Qt 学习之路 2(9):资源文件 豆子 2012年8月31日 Qt 学习之路 2 62条评论 上一章节中我们介绍了如何使用QAction添加动作.其中,我们使用QIcon加载了一张 png ...
- Qt 学习之路 2(8):添加动作
Home / Qt 学习之路 2 / Qt 学习之路 2(8):添加动作 [在WINDOWS10 QTCREATOR MENU添加无效] Qt 学习之路 2(8):添加动作 豆子 ...
- Qt 学习之路 2(5):自定义信号槽
Home / Qt 学习之路 2 / Qt 学习之路 2(5):自定义信号槽 Qt 学习之路 2(5):自定义信号槽 豆子 2012年8月24日 Qt 学习之路 2 131条评论 上一节我们详 ...
- Qt 学习之路 2(74):线程和 QObject
Home / Qt 学习之路 2 / Qt 学习之路 2(74):线程和 QObject Qt 学习之路 2(74):线程和 QObject 豆子 2013年12月3日 Qt 学习之路 2 2 ...
- Qt 学习之路 2(73):Qt 线程相关类
Home / Qt 学习之路 2 / Qt 学习之路 2(73):Qt 线程相关类 Qt 学习之路 2(73):Qt 线程相关类 豆子 2013年11月26日 Qt 学习之路 2 7条评论 希 ...
- Qt 学习之路 2(72):线程和事件循环
Qt 学习之路 2(72):线程和事件循环 <理解不清晰,不透彻> -- 有需求的话还需要进行专题学习 豆子 2013年11月24日 Qt 学习之路 2 34条评论 前面一章我 ...
- Qt 学习之路 2(70):进程间通信
Qt 学习之路 2(70):进程间通信 豆子 2013年11月12日 Qt 学习之路 2 16条评论 上一章我们了解了有关进程的基本知识.我们将进程理解为相互独立的正在运行的程序.由于二者是相互独立的 ...
随机推荐
- Win7系统Matlab2013a安装.m文件不自动关联到MATLAB.exe解决方法
1.在matlab命令行中输入以下代码: cwd=pwd; cd([matlabroot '\toolbox\matlab\winfun\private']); fileassoc('add',{'. ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
- 一个简单的DDraw应用程序2
//------------------------------------------------------------------------- // 文件名 : 6_1.cpp// 创建者 : ...
- 运行所选代码生成器时出错:无效指针(异常来自HRESULT:0x80004003(E_POINTER))
这个是在使用了VS2015 update1学MVC的时候,在controllers的方法添加view时报的一个错误,中文基本搜不到解决方法,然后无奈转到成英文,还好G家的搜索提示补全能力拯救了我的渣英 ...
- greenDaoMaster的学习研究
最近一直在研究一个第三方的开源框架,greenDaoMaster是一个移动开发的ORM框架,由于网上一直查不到使用资料,所以自己摸索总结下用法. 首先需要新建一个JAVA项目用来自动生成文件.需要导入 ...
- leetcode面试准备:Minimum Size Subarray Sum
leetcode面试准备:Minimum Size Subarray Sum 1 题目 Given an array of n positive integers and a positive int ...
- Beej网络socket编程指南
bind()函数 一旦你有一个套接字,你可能要将套接字和机器上的一定的端口关联 起来.(如果你想用listen()来侦听一定端口的数据,这是必要一步--MUD 告 诉你说用命令 "telne ...
- Learning WCF Chapter2 Service Description
While messaging protocols are responsible for message serialization formats,there must be a way to c ...
- cocos2d-x 使用UIWebView加载网页(顺便可以看到如何用OC调C++)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=248 前段时间项目中要微博授权登 ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...