QT Creator4.8.7编译生成的程序正常显示中文的方法
Tofloor
poster avatar
guhongtao2008
deepin
2016-07-01 16:49
Author
新建一个默认的QT Widgets程序,其他文件我就不贴了,只贴这个
我的类名是mywin,文件是mywin.app
#include "mywin.h"
#include "ui_mywin.h"
#include "QLabel"
#include "QTextCodec"//主要是这行
MyWin::MyWin(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MyWin)
{
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));//还有这行,这行的位置应该靠前放置。这里用GBK或GB2312或GB18030都不行,至少我这里不行
    ui->setupUi(this);
    QLabel *label=new QLabel(this);
    label->setText("Hello World!");
    label->setGeometry(20,20,100,25);
    this->setWindowTitle(QObject::tr("我的第一个深度程序"));
}

MyWin::~MyWin()
{
    delete ui;
}


Reply Favorite View the author
All Replies
avatar
h***w@163.com
deepin
2016-07-17 06:04
#1
下面那句的编码应该是跟你源文件保持的时候使用的编码一致,你的源文件是utf8格式的就是utf8,源文件是gb2312就写gb2312.
Reply View the author
avatar
rekols
deepin
2016-07-17 06:22
#2
用qt5吧...
Reply View the author
avatar
macaiyun0629
deepin
2016-07-24 20:43
#3
我4.8,5.6,5.5都从没出现过乱码
https://github.com/mengxing2017/FoodBevManage
我做的项目,一起交流学习
Reply View the author
avatar
Lotuso
deepin
2016-07-24 23:11
#4

什么叫正常显示中文?我一直好奇的是QT为什么不能命令窗口上的程序名字为中文。
Reply View the author
avatar
guhongtao2008
deepin
2016-07-24 23:42
#5
我是在深度15.2里用的QT4.8,在此基础上用QT直接输出中文就是乱码
Reply View the author