QTextStream本身有默认的编码格式,但未测试出它默认的是什么编码,所以在使用它的时候,要为其设置对应的编码,比如从UTF-8编码的文件读取出的,需要为其设置UTF-8,GBK就需要设置成GBK,这样才不会出现乱码,
为QTextStream设置编码的方式是调用setCodec接口
1:instream.setCodec("UTF-8");
QString str = instream.readAll();
2: QTextCodec *codec = QTextCodec::codeForName("UTF-8");
instream.setCodec(codec);
QString str = instream.readAll();