十一、Qt之全局设置字符编码为 UTF-8,解决中文乱码问题

在应用程序的入口函数 main() 中进行设置,如下:

#include "mymainwindow.h"
#include <QApplication>
#include <QTextCodec>


int main(int argc, char *argv[])
{
    //增加全局支持 Uicode 识别支持,解决中文乱码问题
    QTextCodec *code = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(code);
    
    QApplication a(argc, argv);
    MyMainWindow w;
    w.show();

    return a.exec();
}
发布了444 篇原创文章 · 获赞 113 · 访问量 40万+

猜你喜欢

转载自blog.csdn.net/panchang199266/article/details/104043023