在中国大陆,Windows默认的编码是gb2312,而Linux是UTF8;
多数情况下,把Linux上的程序转换至Windows上运行需要进行编码转换才能正常显示;
而其实大可以不必的,同样,文件使用的依然是UTF-8,同样可以在Windows上跑起来,不过有一些事件还需要做的:
1.在main.cpp中添加一段内容:
#include "QTextCodec"
int main(int argc, char *argv[])
{
...
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
...
}
2.在使用QString时,需要使用Qstring str = QString::fromUtf8("content")
3.之后,程序就可以正确的显示中文了。
Ubuntu 10.04下安装Qt4和创建第一个Qt程序:http://www.linuxdiyf.com/linux/1416.html
Qt文件遍历在linux下和windows下的差异:http://www.linuxdiyf.com/linux/16773.html
openSUSE下搭配一个完整的Qt开发环境:http://www.linuxdiyf.com/linux/16077.html
linux下Qt环境的搭建:http://www.linuxdiyf.com/linux/13770.html
ubuntu 15.04 64位安装qt4编译环境并进行编译:http://www.linuxdiyf.com/linux/15266.html