qSetGlobalQHashSeed(100); // set a fixed hash value
QDomDocument doc = QDomDocument();
// add stuff to doc...
// ...
// save doc to file:
QFile file(filename);
QTextStream stream(&file);
stream << doc.toString(4);
file.close();
qSetGlobalQHashSeed(-1); // reset hash seed with new random value.
参考链接:https://stackoverflow.com/questions/21535707/incorrect-order-of-attributes-in-qt-xml
最好解决办法还是用QXmlStreamWriter类去写XML.