qt 学习笔记(1) xml

本文介绍了如何使用QT中的QDomAttr类来获取和修改XML文件中节点的属性。通过具体实例展示了如何访问、更改属性值以及创建新的属性节点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 类。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值