解决QT中中文字符乱码问题,只需在main文件中添加几行代码即可。


#include <QtGui/QApplication>
#include <QTextCodec>
#include "widget.h"

int main(int argc, char *argv[])
{

        QApplication a(argc, argv);
        QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
        QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
        QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
        Widget w;
        w.show();

        return a.exec();
}