qt5.3+vs2013乱码
2024-09-29 19:57:58
解决qt5.3+vs2013乱码,在main函数之前加入
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
简单的说,从Qt5开始,源代码就是默认UTF8编码的。
当然,VC2010编辑器对带BOM的UTF8也是认识,只可惜VC2010编译器根本承认它是UTF8!
//You can write a simple example like this #include <QApplication>
#include <QLabel> #if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label("???ó??ń??");
label.show(); return a.exec();
} //If other people can reproduce your problem, you can file a bug.
较完整的解决方案(增加了Qt4/Qt5和非VC环境的判断):
// Coding: UTF-8(BOM)
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
# pragma execution_character_set("utf-8")
#endif #include <QApplication>
#include <QTextCodec>
#include <QLabel> int main(int argc, char* argv[])
{
QApplication app(argc, argv); #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
#if defined(_MSC_VER) && (_MSC_VER < 1600)
QTextCodec::setCodecForTr(QTextCodec::codecForName("GB18030-0"));
#else
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif
#endif QLabel *label = new QLabel(QObject::tr("你好!"));
label->show(); return app.exec();
}
另外:Qt4/Qt5/Linux: 只要是默认的UTF8环境, 应该都没问题
其实这个问题不是Qt特有的, 追根溯源还是C/C++和编译器的问题.即使是支持UTF16的Java也同样难逃此问题.
来自:http://blog.163.com/qimo601@126/blog/static/1582209320143115334438/
最新文章
- strftime 日期时间格式化
- C#对象克隆介绍
- atitit.软件开发方法总结O6
- MySql 申明变量以及赋值
- input:text 的value 和 attribute(&#39;value&#39;) 不是一回事
- 特定用户QQ群聊天记录导出的实现
- (转)Const,Const函数,Const变量,函数后面的Const
- SCSI接口图文详解
- oracle 开发笔记“跨数据库查询复制”
- [置顶] HMM Tutorial 隐马尔科夫模型
- ThinkPHP中处理Layout模板的问题
- css3写出飘雪花特效
- hadoop解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.问题
- sort();对结构体数组的排序
- 设置IE浏览器跨域访问数据
- Springboot 的错误处理功能的实现
- CSS 图像高级 Css Sprites
- Java数据库操作(MySQL与SQLserver)
- 便于记忆的SA构造
- Spring-boot(二)--thymeleaf