QDomDocument doc;
if (!doc.setContent(&file))
{
file.close();
return ;
}
执行过程中doc.setContent(&file)一直返回false,首先判断路径没错。
调试:
if(!doc.setContent(&file,true,&errorStr,&errorLine,&errorCol))
{
qDebug() << errorStr << "line: " << errorLine << "col: " << errorCol;
file.close();
return ;
}
发现出现错误的地方是1行20列,
instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");即encoding前面有个空格,加上就行(教程里面没有空格http://www.qter.org/forum.php?mod=viewthread&tid=189&extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline%26orderby%3Ddateline)