Qt unicode解码
#include <QCoreApplication>
#include <QFile>
#include <QTextStream>
#include<QDebug>
QString unicodeToQString(QString rawstr)
{
do {
int idx = rawstr.indexOf("\\u");
QString strHex = rawstr.mid(idx, 6);
strHex = strHex.replace("\\u", QString());
int nHex = strHex.toInt(0, 16);
rawstr.replace(idx, 6, QChar(nHex));
} while (rawstr.indexOf("\\u") != -1);
return rawstr;
}
int main()
{
int count=0;
QFile inputFile("input.txt");
QFile outputFile("output.txt");
if (inputFile.open(QIODevice::ReadOnly | QIODevice::Text) &&
outputFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream in(&inputFile);
QTextStream out(&outputFile);
while (!in.atEnd())
{
QString line = in.readLine();
line=unicodeToQString(line);
out << line << endl;
count++;
qDebug()<<"完成"<<count<<"条"<<endl;
}
inputFile.close();
outputFile.close();
}
return 0;
}