zoukankan      html  css  js  c++  java
  • 解决Qt程序发布时中文乱码问题

    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,如果用到其它插件也相应复制其它插件目录发布.

  • 相关阅读:
    拥有最多糖果的孩子
    求1+2+…+n
    网络-中间代理
    Header中的Referer属性表示
    ios13.4post请求出现网错错误 network err
    10.8&10.10
    9.23&9.27
    9.16&9.19
    校内模拟赛划水报告(9.9,9.11)
    男人八题 划水题解
  • 原文地址:https://www.cnblogs.com/guobbs/p/3999858.html
Copyright © 2011-2022 走看看