QT读取文件出现乱码的问题
2015-04-01 14:58
399 查看
QT中QString保存读取的内容出现乱码是因为编码方式不正确,给出以下两种方法:
1、 QTextCodec::setCodecForCStrings( QTextCodec::codecForName("GBK"));
QString str;
QFile file("./test.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text ))
{
return;
}
while( file.atEnd() == 0 )
{
QString linestr;
linestr = file.readLine();
str += linestr;
str += "\r\n";
}
读取完成后打印出str
2、 QString str;
QFile file("./test.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text ))
{
return;
}
QTextCodec *code=QTextCodec::codecForName("GBK");
QTextStream rstream( &file );
rstream.setCodec( code );
while( rstream.atEnd() == 0 )
{
QString linestr;
linestr = rstream.readLine();
str += linestr;
str += "\r\n";
}
读取完成后打印str
1、 QTextCodec::setCodecForCStrings( QTextCodec::codecForName("GBK"));
QString str;
QFile file("./test.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text ))
{
return;
}
while( file.atEnd() == 0 )
{
QString linestr;
linestr = file.readLine();
str += linestr;
str += "\r\n";
}
读取完成后打印出str
2、 QString str;
QFile file("./test.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text ))
{
return;
}
QTextCodec *code=QTextCodec::codecForName("GBK");
QTextStream rstream( &file );
rstream.setCodec( code );
while( rstream.atEnd() == 0 )
{
QString linestr;
linestr = rstream.readLine();
str += linestr;
str += "\r\n";
}
读取完成后打印str
相关文章推荐
- CFile读取文件时末尾出现乱码的问题
- IO 流读取文件时候出现乱码 文件编码格式问题 怎么转换解决方法
- 读取文件时出现中文乱码问题的解决
- qt读取txt文件 ,解决汉字乱码问题
- Learning Python 015 Python3解决问题:读取文件时,出现乱码或者“UnicodeDecodeError 'gbk' codec can't decode” 错误
- java:InputStream读取文件时出现中文乱码问题
- 安卓(JAVA)读取Mp3文件中的歌曲信息(及readLine()出现乱码问题的解决方法)
- IO 流读取文件时候出现乱码 文件编码格式问题 怎么转换解决方法
- spring使用@Value注解读取.properties文件时出现中文乱码问题的解决
- 使用CStdioFile 读取Unicode文件时出现乱码问题解决方案
- Java:InputStream读取文本文件内容出现乱码问题的解决方法
- 关于javascript从txt文件中读取内容出现乱码的问题
- 读取java的配置文件.properties出现乱码问题
- VS读取文件或写入文件时出现中文乱码问题
- 关于使用IDEA读取txt文件出现中文乱码的问题
- 在QT中读取数据到MYSQL出现乱码的问题。
- qt读取txt文件 ,解决汉字乱码问题
- 关于Spring boot中读取属性配置文件出现中文乱码的问题的解决
- QT 打开txt文件以及出现的乱码问题
- Qt中显示html文件出现乱码的问题