VS2013+QT5.3 中文乱码和中文路径不识别

http://blog.csdn.net/brave_heart_lxl/article/details/7186631

ubun图中文乱码

https://blog.csdn.net/u013007900/article/details/50156115

方法一

QTextCodec * BianMa = QTextCodec::codecForName ( "GBK" );

QMessageBox::information(this, "提示", BianMa->toUnicode("中文显示!"));

  

方法二

我们也可以通过QString定义的静态函数,先转换成Unicode类型: 
QString::fromLocal8Bit("提示") 

  

对于中文常量,使用QStringLiteral即可解决,对于字符串变量,使用QString自带函数也可以轻松解决。

const char* info = "中文显示"; //不支持

QString strInfo = QStringLiteral(info);//支持

QString strInfo = QString::fromLocal8Bit(info);

  

 

 中文乱码

本方案适用于VS2013+QT5.3环境(编译器是VC)

using namespace std;
# pragma execution_character_set("utf-8")
//文件的开头要声明字符编码UTF-8,这样输出中文字符串就能显示正常。
qDebug() << " 连接交易前置...成功" ;

  

直接输出字符串是没问题了,但遇到char*[]这样的字符数组的时候显示中文还是会有问题,应该是VS环境下默认是GBK编码

在MAIN函数中添加设置本地编码GBK

QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));

  在遇到字符数组的时候使用

QString::fromLocal8Bit(pRspInfo->ErrorMsg)

  

进行转换便能正常显示中文。

中文路径不识别

头文件:#include <QTextCodec>

QString fileName = QFileDialog::getOpenFileName(NULL,"filename","","");  
  
QTextCodec *code = QTextCodec::codecForName("GB2312");//解决中文路径问题  
std::string name = code->fromUnicode(fileName).data();  
  
if(fileName.isEmpty())  
{  
    return;  
}  
  
org = imread(name, 1);  

  

原文地址:https://www.cnblogs.com/kekeoutlook/p/7473048.html