Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
QT Creator4.8.7编译生成的程序正常显示中文的方法
Apps Section
987
views ·
5
replies ·
To
floor
Go
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
Like 0
Favorite
View the author
All Replies
h***w@163.com
deepin
2016-07-17 06:04
#1
下面那句的编码应该是跟你源文件保持的时候使用的编码一致,你的源文件是utf8格式的就是utf8,源文件是gb2312就写gb2312.
Reply
Like 0
View the author
rekols
deepin
2016-07-17 06:22
#2
用qt5吧...
Reply
Like 0
View the author
macaiyun0629
deepin
2016-07-24 20:43
#3
我4.8,5.6,5.5都从没出现过乱码
https://github.com/mengxing2017/FoodBevManage
我做的项目,一起交流学习
Reply
Like 0
View the author
Lotuso
deepin
2016-07-24 23:11
#4
什么叫正常显示中文?我一直好奇的是QT为什么不能命令窗口上的程序名字为中文。
Reply
Like 0
View the author
guhongtao2008
deepin
2016-07-24 23:42
#5
我是在深度15.2里用的QT4.8,在此基础上用QT直接输出中文就是乱码
Reply
Like 0
View the author
Please
sign
in first
Featured Collection
Change
Nuntia - Modern IMAP/SMTP mail client for Deepin (Beta tester wanted!)
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
Adding a Dancing Spectrum Bar to the Deepin Taskbar | deepin-spectrum
Popular Events
More
我的类名是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;
}