1、保存文件格式为UTF-8
2、文件流打开时设置
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "XmlPrivate load fail" << fileName;
return false;
}
// 以文本流的形式访问
QTextStream stream(&file);
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
stream.setCodec(codec);
QString content = stream.readAll();
file.close();
// DOM结构解析
QDomDocument domDocument;
domDocument.setContent(content);
QDomElement rootElement = domDocument.documentElement();
rootNode = this->fromDomElement(rootElement);