Qt中修改XML文件中的节点值解决方案

Qt中修改XML文件中的节点值
不能修改XML文件的节点
xml文件:
<kdevelop>
      <general>
          <author>zeki</author>
          <email>caizhiming@tom.com</email>
      </general>
</kdevelop>

我写的源码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtXml>
#include <QDebug>
#include <QFile>
#include <QTextStream>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QDomDocument dom;
    QFile *file=new QFile("/home/qust/qt/XML/2.xml");
    if(file->open(QIODevice::ReadOnly|QIODevice::WriteOnly))
    {
        dom.setContent(file);

    }

    QDomNodeList email=dom.documentElement().elementsByTagName("email");
    qDebug()<<email.count();//打印 1
    qDebug()<<email.item(0).toElement().text();//打印caizhiming@tom.com
    QDomNode oldnode =email.item(0);

    QDomText newnode=dom.createTextNode("99629968@qq.com");
    email.at(0).replaceChild(newnode,oldnode);
    QTextStream out(file);
    dom.save(out,4);
    file->close();

}

MainWindow::~MainWindow()
{
    delete ui;
}
不能修改XML文件,运行后打开xml文件出现

XML解析错误:废弃 document 元素之后的内容 
位置:file:///home/qust/qt/XML/2.xml 
行:8,列:1:<?xml version='1.0'?>

^

该怎么修改xml 中节点的值呢??为什么不能使用setNodeValue()方法来修改接点的值???

大家帮帮忙,谢谢!!!

------解决方案--------------------
中间是TextNode。你修改它的值。
------解决方案--------------------
一般是操作节点的问题.
------解决方案--------------------
dom.setContent(file);
这一行就出错了吧,你的2.xml是不是有问题?

------解决方案--------------------
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QDialog>
#include <QFile>
#include <QDebug>
#include <QDomDocument>
#include <QFile>
QDomDocument m_doc;
bool  changeSave();
bool openXmlFile(QString FilePath);

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    changeSave();
    return a.exec();
}
bool openXmlFile(QString FilePath)
{
    QFile file( FilePath );
    if( !file.open( QFile::ReadOnly 
------解决方案--------------------
 QFile::Text  ) )
    {
        qDebug() << QObject::tr("error::ParserXML->OpenXmlFile->file.open->%s\n") << FilePath;
        
        return false;
    }
    
    if( !m_doc.setContent( &file ) )
    {
        qDebug() << QObject::tr("error::ParserXML->OpenXmlFile->doc.setContent\n") << FilePath;
        
        file.close();
        return false;
    }
    file.close();
    return true;
}
bool  changeSave()
{
    
    if(!openXmlFile("I:/q.xml"))
    {
        return false;
    }
    //修改保存xml
    QDomElement root = m_doc.documentElement();
    if(root.tagName()!= "kdevelop")
        return false;