本页内容

QOpcUaGenericStructValue Class

存储通用 OPC UA 结构化类型的值。更多...

头文件: #include <QOpcUaGenericStructValue>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpcUa)
target_link_libraries(mytarget PRIVATE Qt6::OpcUa)
qmake: QT += opcua
自: Qt 6.7

公共函数

QOpcUaGenericStructValue()
QOpcUaGenericStructValue(const QString &typeName, const QString &typeId, const QOpcUaStructureDefinition &definition)
QOpcUaGenericStructValue(const QString &typeName, const QString &typeId, const QOpcUaStructureDefinition &definition, const QHash<QString, QVariant> &fields)
QOpcUaGenericStructValue(const QOpcUaGenericStructValue &other)
QOpcUaGenericStructValue(QOpcUaGenericStructValue &&other)
~QOpcUaGenericStructValue()
QHash<QString, QVariant> fields() const
QHash<QString, QVariant> &fieldsRef()
void setFields(const QHash<QString, QVariant> &fields)
void setStructureDefinition(const QOpcUaStructureDefinition &structureDefinition)
void setTypeId(const QString &typeId)
void setTypeName(const QString &typeName)
QOpcUaStructureDefinition structureDefinition() const
void swap(QOpcUaGenericStructValue &other)
QString toString() const
QString typeId() const
QString typeName() const
operator QVariant() const
QOpcUaGenericStructValue &operator=(QOpcUaGenericStructValue &&other)
QOpcUaGenericStructValue &operator=(const QOpcUaGenericStructValue &rhs)
bool operator!=(const QOpcUaGenericStructValue &lhs, const QOpcUaGenericStructValue &rhs)
QDebug operator<<(QDebug debug, const QOpcUaGenericStructValue &s)
bool operator==(const QOpcUaGenericStructValue &lhs, const QOpcUaGenericStructValue &rhs)

详细说明

该类保存一个通用的 OPC UA 结构体值,该值由命名字段及其值组成,这些字段的值可以是内置类型或其子类型,也可以是其他嵌套的通用结构体。此外,还包含一些元信息,例如类型 ID 以及该类对象所包含类型的结构定义。

它用作解码结果的返回类型,以及QOpcUaGenericStructHandler 方法的编码输入类型。

对于带有可选字段的结构体,fields() 列表中仅包含已指定的字段。若要在编码过程中省略某个可选字段,则该字段不得出现在fields()列表中。 对于从 Union 类型派生的结构体,必须仅指定其中一个字段。解码类型中fields() 列表中的唯一条目将决定类型定义中哪个字段(如有)被指定。

示例:

// 解码一个扩展对象
QOpcUaGenericStructValue value=decoder.decode(extensionObject,success);

// 打印必填字段的值
qDebug() << value.fields().value("MyField").value<QOpcUaLocalizedText>();

// 输出可选字段的值
if(value.fields().contains("MyOptionalField"))
    qDebug() << value.fields().value("MyField").value<QOpcUaQualifiedName>();

// 获取字段的嵌套结构体
const autounionMember=value.fields().value("MyUnionMember").value<QOpcUaGenericStructValue>();

// 输出指定字段
if(unionMember.fields().contains("UnionMember1"))
    qDebug() << unionMember.fields().value("UnionMember1").toInt();
else if(unionMember.fields().contains("UnionMember2"))
    qDebug() << unionMember.fields().value("UnionMember2").toDouble();
else
    qDebug() << "Empty union";

成员函数文档

QOpcUaGenericStructValue::QOpcUaGenericStructValue()

构建一个通用的结构体值。

QOpcUaGenericStructValue::QOpcUaGenericStructValue(const QString &typeName, const QString &typeId, const QOpcUaStructureDefinition &definition)

根据typeName 、typeId 和definition 构建一个通用的结构体值。

QOpcUaGenericStructValue::QOpcUaGenericStructValue(const QString &typeName, const QString &typeId, const QOpcUaStructureDefinition &definition, const QHash<QString, QVariant> &fields)

根据typeName 、typeId 、definition 和fields 构建一个通用结构体值。

QOpcUaGenericStructValue::QOpcUaGenericStructValue(const QOpcUaGenericStructValue &other)

根据other 构建一个泛型结构体值。

[constexpr noexcept default] QOpcUaGenericStructValue::QOpcUaGenericStructValue(QOpcUaGenericStructValue &&other)

从other 移动并构造一个新的泛型结构体值。

注意: 被移动的对象 other 将处于部分形成状态,在此状态下,唯一有效的操作是销毁和赋值新值。

[noexcept] QOpcUaGenericStructValue::~QOpcUaGenericStructValue()

销毁此通用结构体值对象。

QHash<QString, QVariant> QOpcUaGenericStructValue::fields() const

返回此通用结构体值的字段。

另请参阅 setFields()。

QHash<QString, QVariant> &QOpcUaGenericStructValue::fieldsRef()

返回对此通用结构体值的字段的引用。

void QOpcUaGenericStructValue::setFields(const QHash<QString, QVariant> &fields)

将此通用结构体值的字段设置为fields 。

另请参阅 fields()。

void QOpcUaGenericStructValue::setStructureDefinition(const QOpcUaStructureDefinition &structureDefinition)

将此泛型结构体值的结构定义设置为structureDefinition 。

另请参阅 structureDefinition()。

void QOpcUaGenericStructValue::setTypeId(const QString &typeId)

将此通用结构体值的类型节点 ID 设置为typeId 。

另请参阅 typeId()。

void QOpcUaGenericStructValue::setTypeName(const QString &typeName)

将此泛型结构体值的类型名称设置为typeName 。

另请参阅 typeName()。

QOpcUaStructureDefinition QOpcUaGenericStructValue::structureDefinition() const

返回此泛型结构体值的结构定义。

另请参阅 setStructureDefinition()。

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

将通用结构体值对象other 与该通用结构体值对象互换。此操作速度极快,且绝不会失败。

QString QOpcUaGenericStructValue::toString() const

返回该泛型结构体值的字符串表示形式。

QString QOpcUaGenericStructValue::typeId() const

返回此泛型结构体值的类型节点 ID。

另请参阅 ` setTypeId()`。

QString QOpcUaGenericStructValue::typeName() const

返回此泛型结构体值的类型名称。

另请参阅 ` setTypeName()`。

QOpcUaGenericStructValue::operator QVariant() const

返回一个包含此泛型结构体值的QVariant 。

[noexcept] QOpcUaGenericStructValue &QOpcUaGenericStructValue::operator=(QOpcUaGenericStructValue &&other)

将other 通过移动赋值给此QOpcUaGenericStructValue 实例。

注意: 被移动的源对象 other 将处于部分初始化状态,在此状态下,唯一有效的操作是销毁和赋值新值。

QOpcUaGenericStructValue &QOpcUaGenericStructValue::operator=(const QOpcUaGenericStructValue &rhs)

将此通用结构体的rhs 字段设置为指定值。

相关的非成员

[noexcept] bool operator!=(const QOpcUaGenericStructValue &lhs, const QOpcUaGenericStructValue &rhs)

如果 `lhs ` 不等于 `rhs`,则返回 `true `。

QDebug operator<<(QDebug debug, const QOpcUaGenericStructValue &s)

将s 的字符串表示形式输出到debug 中。

[noexcept] bool operator==(const QOpcUaGenericStructValue &lhs, const QOpcUaGenericStructValue &rhs)

如果 `lhs ` 等于 `rhs`,则返回 `true `。

© 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.