本页内容

QXmlAttributes Class

QXmlAttributes 类提供了 XML 属性。更多内容...

标题: #include <QXmlAttributes>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
qmake: QT += core5compat

注意:该类中的所有函数均为可重入的。

公共函数

QXmlAttributes()
QXmlAttributes(const QXmlAttributes &)
QXmlAttributes(QXmlAttributes &&)
virtual ~QXmlAttributes()
void append(const QString &qName, const QString &uri, const QString &localPart, const QString &value)
void clear()
int count() const
int index(const QString &qName) const
int index(QLatin1String qName) const
int index(const QString &uri, const QString &localPart) const
int length() const
QString localName(int index) const
QString qName(int index) const
void swap(QXmlAttributes &other)
QString type(int index) const
QString type(const QString &qName) const
QString type(const QString &uri, const QString &localName) const
QString uri(int index) const
QString value(int index) const
QString value(QLatin1String qName) const
QString value(const QString &qName) const
QString value(const QString &uri, const QString &localName) const
QXmlAttributes &operator=(QXmlAttributes &&)
QXmlAttributes &operator=(const QXmlAttributes &)

详细说明

如果通过QXmlContentHandler::startElement()报告属性,则使用本类来传递属性值。

使用index() 查找列表中属性的位置,使用count() 获取属性数量,并使用clear() 删除属性。 可通过append() 添加新属性。使用type() 获取属性的类型,使用value() 获取其值。可通过localName() 或qName() 获取属性的名称,并通过uri() 获取其命名空间 URI。

成员函数文档

QXmlAttributes::QXmlAttributes()

构建一个空的属性列表。

[noexcept default] QXmlAttributes::QXmlAttributes(const QXmlAttributes &)

复制并构造一个QXmlAttributes 实例。

[noexcept default] QXmlAttributes::QXmlAttributes(QXmlAttributes &&)

通过Move操作构造一个QXmlAttributes 实例。

[virtual noexcept] QXmlAttributes::~QXmlAttributes()

销毁 attributes 对象。

void QXmlAttributes::append(const QString &qName, const QString &uri, const QString &localPart, const QString &value)

将一个新的属性条目追加到属性列表中。该属性的限定名称为qName ,命名空间 URI 为uri ,本地名称为localPart 。该属性的值为value 。

另请参阅 qName()、uri()、localName() 以及value()。

void QXmlAttributes::clear()

清除属性列表。

另请参阅 append()。

int QXmlAttributes::count() const

返回列表中的属性个数。该函数与length() 功能相同。

int QXmlAttributes::index(const QString &qName) const

根据限定名qName 查找属性的索引。

返回该属性的索引;若未找到该属性,则返回 -1。

int QXmlAttributes::index(QLatin1String qName) const

这是一个重载函数。

int QXmlAttributes::index(const QString &uri, const QString &localPart) const

根据命名空间名称查找属性的索引。

uri 指定命名空间 URI;如果该名称没有命名空间 URI,则指定空字符串。localPart 指定属性的本地名称。

返回该属性的索引;若未找到,则返回 -1。

这是一个重载函数。

int QXmlAttributes::length() const

返回列表中的属性数量。

另请参阅 count()。

QString QXmlAttributes::localName(int index) const

查询位于位置index 处的属性的本地名称。如果未进行命名空间处理,则本地名称为空字符串。

QString QXmlAttributes::qName(int index) const

查询位于位置index 的该属性的 XML 1.0 限定名。

[noexcept] void QXmlAttributes::swap(QXmlAttributes &other)

将this 替换为other 。

QString QXmlAttributes::type(int index) const

查询位于位置index 的属性的类型。

目前仅返回“CDATA”。

QString QXmlAttributes::type(const QString &qName) const

查询全限定名qName 的属性类型。

目前仅返回“CDATA”。

这是一个重载函数。

QString QXmlAttributes::type(const QString &uri, const QString &localName) const

根据命名空间名称查询属性的类型。

uri 指定命名空间 URI,localName 指定本地名称。如果名称没有命名空间 URI,则将uri 设为空字符串。

目前仅返回“CDATA”。

这是一个重载函数。

QString QXmlAttributes::uri(int index) const

查询位于位置index 的属性的命名空间 URI。如果未进行命名空间处理,或者该属性没有命名空间,则命名空间 URI 为空字符串。

QString QXmlAttributes::value(int index) const

返回位于位置index 的属性的值。该索引必须是一个有效的位置(即 0 <=index <count())。

QString QXmlAttributes::value(QLatin1String qName) const

返回限定名称qName 对应的属性值;如果给定名称下不存在该属性,则返回空字符串。

这是一个重载函数。

QString QXmlAttributes::value(const QString &qName) const

返回限定名称qName 对应的属性值;如果给定名称下不存在该属性,则返回空字符串。

这是一个重载函数。

QString QXmlAttributes::value(const QString &uri, const QString &localName) const

根据命名空间名称返回属性的值。

uri 指定命名空间 URI;如果该名称没有命名空间 URI,则指定空字符串。localName 指定属性的本地名称。

这是一个重载函数。

[noexcept default] QXmlAttributes &QXmlAttributes::operator=(QXmlAttributes &&)

将other 通过Move操作赋值给此QXmlAttributes 实例。

[noexcept default] QXmlAttributes &QXmlAttributes::operator=(const QXmlAttributes &)

将other 复制并赋值给此QXmlAttributes 实例。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.