• 3412阅读
  • 0回复

xml内添加节点  急!!! [复制链接]

上一主题 下一主题
离线jiang_198586
 

只看楼主 正序阅读 楼主  发表于: 2010-03-11
为什么下面xml内添加节点的代码,不能实现呢?而且没有编译错误,但是就是不能加入新节点
void config::addnode(){
    QFile file(":/linkconfig/ifisconfig.xml");
    if(file.exists(":/linkconfig/ifisconfig.xml")){
       QDomDocument doc;
       file.open(QIODevice::ReadOnly);
       doc.setContent(file.readAll());
       file.close();
       QDomNode root = doc.documentElement();

       QDomElement subname =  doc.createElement(tr("sub_name"));
       QDomElement host = doc.createElement(tr("Host"));
        QDomText text_host = doc.createTextNode(tr("address"));

       root.appendChild(subname);
       subname.appendChild(host);
       host.appendChild(text_host);

       file.open(QIODevice::WriteOnly);
       QTextStream out(&file);
       root.save(out,3);

    }
    else{......... }
}
快速回复
限100 字节
 
上一个 下一个