QT文本操作中文乱码,如何解?
牧牛童子 2019-04-02 02:01:00 QTextStream打开一文本文件,为何总是第一次读出来中文是乱码(逐行读、打印输出),然后再读一遍或两遍(读取操作再重复),中文就能正常读出?
何故?
QFile f01("test.txt");
if(!f01.open(QIODevice::ReadOnly | QIODevice::Text))
{
//cout << "Open failed." << endl;
QMessageBox::warning(nullptr,"提示","打开文件时出现异常!");
return -1;
}
QTextStream txtInput(&f01);
while(!txtInput.atEnd())
{
QString lineStr;
lineStr = txtInput.readLine();
qDebut()<<lineStr;
}