当发布有中文显示的界面时 ,往往需要设置Qt的字符编码插件:
QStringList libPaths;
#if defined( Q_OS_WIN32 )
libPaths << app.applicationDirPath() + "/plugins/";
#elif defined( Q_OS_MACX )
libPaths << app.applicationDirPath() + "/../PlugIns";
#endif
QApplication::setLibraryPaths(libPaths);
在main函数中添加如上代码,再将需要的plugin从Qt目录下拷贝过来,程序打包发给别人时,中文乱码就会解决啦!
同时需要设置程序的字符编码:
QTextCodec *codec = QTextCodec::codecForName("GB2312");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
from: sunfrank2012#gmail.com