qt 学习笔记(1) xml

来源:互联网 发布:php门户网站 编辑:程序博客网 时间:2024/05/18 00:27

qt 获得xml 节点属性,

The QDomAttr class represents one attribute of a QDomElement.  //描绘,(抽象地)表现 2. 象征;表示 3. 作为...的代表 4.

For example, the following piece of XML produces an element with no children, but two attributes:

 <link href="http://qt.nokia.com" color="red" />

You can access the attributes of an element with code like this:

 QDomElement e = //... //... QDomAttr a = e.attributeNode("href"); cout << a.value() << endl;                // prints "http://qt.nokia.com" a.setValue("http://qt.nokia.com/doc"); // change the node's attribute QDomAttr a2 = e.attributeNode("href"); cout << a2.value() << endl;               // prints "http://qt.nokia.com/doc"

This example also shows that changing an attribute received from an element changes the attribute of the element. If you do not want to change the value of the element's attribute you must use cloneNode() to get an independent copy of the attribute.

QDomAttr can return the name() and value() of an attribute. An attribute's value is set with setValue().



//The readyRead() signal is emitted every time a new chunk of data has arrived.//数据块

属性的添加:

QDomAttr QDomElement::setAttributeNode ( const QDomAttr & newAttr )

Adds the attribute newAttr to this element.

If the element has another attribute that has the same name as newAttr, this function replaces that attribute and returns it; otherwise the function returns a null attribute.

新建属性:

QDomAttr QDomDocument::createAttribute ( const QString & name )

Creates a new attribute called name that can be inserted into an element, e.g. using QDomElement::setAttributeNode().

现在遇到不能修改XML文件,apt说要用.ini文件保存参数。QSetting 类。


原创粉丝点击