Qt程序的文字編碼,是通過插件來解決的,所以我們發布的時候需要把相應的插件也發布出去,在開發者電腦上程序會自動從插件目錄加載到插件,但是如果發布給別的電腦使用,需要手動指定插件路徑,如下所示:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString strLibPath = a.applicationDirPath();
strLibPath += "/plugins"; //plugins就是插件目錄
a.addLibraryPath(strLibPath); //此代碼必須在QTextCodec的代碼前執行
QTextCodec *pcodec = QTextCodec::codecForName("gb2312");
QTextCodec::setCodecForCStrings(pcodec);
QTextCodec::setCodecForLocale(pcodec);
QTextCodec::setCodecForTr(pcodec);
CWinMain w;
w.show();
return a.exec();
}
備注:這個plugins目錄就是Qt SDK(注意不是QtCreator的)的plugins目錄,對於文字編碼的子目錄是codecs,如果用到其它插件也相應復制其它插件目錄發布.
http://www.cnblogs.com/guobbs/p/3999858.html

