QOpcUaGenericStructHandler Class

서버의 데이터 유형을 읽고 확장 객체에서 일반 구조체를 디코딩/인코딩합니다. 더 보기...

Header: #include <QOpcUaGenericStructHandler>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpcUa)
target_link_libraries(mytarget PRIVATE Qt6::OpcUa)
qmake: QT += opcua
이후: Qt 6.7
상속합니다: QObject

공개 유형

enum class DataTypeKind { Unknown, Struct, Enum, Other }

공용 함수

QOpcUaGenericStructHandler(QOpcUaClient *client, QObject *parent = nullptr)
bool addCustomEnumDefinition(const QOpcUaEnumDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)
bool addCustomStructureDefinition(const QOpcUaStructureDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)
QOpcUaGenericStructValue createGenericStructValueForTypeId(const QString &typeId)
QOpcUaGenericStructHandler::DataTypeKind dataTypeKindForTypeId(const QString &id) const
std::optional<QOpcUaGenericStructValue> decode(const QOpcUaExtensionObject &extensionObject) const
std::optional<QOpcUaExtensionObject> encode(const QOpcUaGenericStructValue &value)
QOpcUaEnumDefinition enumDefinitionForTypeId(const QString &id) const
bool initialize()
(since 6.7) bool initialized() const
bool isAbstractTypeId(const QString &id) const
QOpcUaStructureDefinition structureDefinitionForBinaryEncodingId(const QString &id) const
QOpcUaStructureDefinition structureDefinitionForTypeId(const QString &id) const
QString typeIdForBinaryEncodingId(const QString &id) const
QString typeNameForBinaryEncodingId(const QString &id) const
QString typeNameForTypeId(const QString &id) const

신호

void initializedChanged(bool initialized)

상세 설명

OPC UA에서 사용되는 바이너리 데이터 인코딩은 작은 메시지 크기를 염두에 두고 설계되었으며 데이터 구조에 대한 정보를 포함하지 않습니다. 즉, 디코더가 데이터 버퍼를 디코딩하려면 인코딩된 데이터의 구조를 미리 알고 있어야 합니다.

OPC UA 1.04부터 DataType 노드 클래스의 노드는 구조화된 유형의 필드와 열거형 값의 이름 매핑에 대한 정보를 포함하는 DataTypeDefinition 속성을 가질 수 있습니다. 이를 통해 클라이언트는 기본 제공 유형을 디코딩하는 방법에 대한 지식과 함께 외부 지식에 의존하지 않고도 일반 사용자 정의 구조화 유형을 디코딩할 수 있습니다.

QOpcUaGenericStructHandler는 BaseDataType에서 시작하여 HasSubtype 참조를 따라 서버의 유형 계층구조를 탐색하고 노드의 DataTypeDefinition 속성을 읽습니다.

DataTypeDefinition 속성에 QOpcUaStructureDefinition 값이 있는 구조화된 유형의 경우 이를 포함하는 확장 개체를 자동으로 디코딩할 수 있습니다. 기본 제공 유형이 있는 필드 또는 C++ 데이터 클래스가 존재하는 유형은 해당 Qt OPC UA 유형으로 역직렬화되고, 다른 일반 구조체는 중첩된 QOpcUaGenericStructValue 으로 직렬화됩니다. 중첩된 모든 일반 구조체 값은 서버에 QOpcUaStructureDefinition 이 있어야 하며 그렇지 않으면 디코딩에 실패합니다.

사용자 정의 구조체를 인코딩할 때도 동일한 조건이 적용됩니다.

사용자 정의 구조체를 디코딩하는 예제입니다:

QOpcUaGenericStructHandler handler(opcuaClient); handler.initialize();QObject::connect(&handler, &.QOpcUaGenericStructHandler::initializedChanged, [opcuaClient, &handler](bool initialized) { if (!initialized) return; auto node =  opcuaClient->node("ns=4;i=3003"); // open62541-testserver의 사용자 정의 구조체 테스트 노드 node->readValueAttribute();    QObject::connect(node, &QOpcUaNode::attributeRead, [node, &handler](QOpcUa::NodeAttributes attr) { if (!attr.testFlag(QOpcUa::NodeAttribute::Value) ||  node->valueAttributeError() != QOpcUa::UaStatusCode::Good) return; auto extObj =  node->valueAttribute().value<QOpcUaExtensionObject>();        qDebug() << "Got object of type" << handler.typeNameForBinaryEncodingId(extObj.encodingTypeId());

       const auto result = handler.decode(extObj); if (!result) return;
        qDebug() << *result;
    }); });

사용자 정의 구조체를 인코딩하는 예제입니다:

QOpcUaGenericStructHandler handler(opcuaClient);
handler.initialize();

QObject::connect(&handler, &QOpcUaGenericStructHandler::initializedChanged, [opcuaClient, &handler](bool initialized) {
    if (!initialized)
        return;

    QOpcUaGenericStructValue value = handler.createGenericStructValueForTypeId("ns=4;i=3006");
    value.fieldsRef()["MandatoryMember"] = 23.0;
    value.fieldsRef()["OptionalMember"] = 42.0;

    const auto ext = handler.encode(value);

    if (!ext)
        return;

    // Use the extension object to write a node's value attribute, in a method parameter, etc...
});

멤버 타입 문서

enum class QOpcUaGenericStructHandler::DataTypeKind

이 열거형 유형은 데이터 유형 노드의 데이터 유형 종류를 지정합니다.

Constant설명
QOpcUaGenericStructHandler::DataTypeKind::Unknown0유형 노드 ID를 알 수 없습니다.
QOpcUaGenericStructHandler::DataTypeKind::Struct1유형 노드 ID가 구조형 유형에 속합니다.
QOpcUaGenericStructHandler::DataTypeKind::Enum2타입 노드 ID가 열거형 타입에 속합니다.
QOpcUaGenericStructHandler::DataTypeKind::Other3타입 노드 ID가 구조체나 열거형이 아닌 타입(다른 내장 타입 또는 그 하위 타입)에 속합니다.

멤버 함수 문서

[explicit] QOpcUaGenericStructHandler::QOpcUaGenericStructHandler(QOpcUaClient *client, QObject *parent = nullptr)

client 에 대한 일반 구조체 핸들러를 구축합니다.

bool QOpcUaGenericStructHandler::addCustomEnumDefinition(const QOpcUaEnumDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)

알려진 유형에 사용자 정의 열거형 정의 definition 를 추가합니다. 이는 서버가 구조 정의를 노출하지 않는 사용자 정의 구조를 지원하는 데 사용할 수 있습니다. 적절한 디코딩 및 인코딩을 위해서는 definition, typeIdname 매개 변수가 필요합니다. isAbstract 이 설정되어 있으면 유형을 인코딩 및 디코딩할 수 없습니다.

열거형 정의가 성공적으로 추가되면 true 을 반환합니다.

bool QOpcUaGenericStructHandler::addCustomStructureDefinition(const QOpcUaStructureDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)

알려진 유형에 사용자 정의 구조 정의 definition 를 추가합니다. 이는 서버가 구조 정의를 노출하지 않는 사용자 정의 구조를 지원하는 데 사용할 수 있습니다. 적절한 디코딩 및 인코딩을 위해서는 definition, typeIdname 매개변수가 필요합니다. isAbstract 이 설정되어 있으면 유형을 인코딩 및 디코딩할 수 없습니다.

구조 정의가 성공적으로 추가되면 true 을 반환합니다.

QOpcUaGenericStructValue QOpcUaGenericStructHandler::createGenericStructValueForTypeId(const QString &typeId)

typeId 에 해당하는 구조체 정의, 유형 ID 및 유형 이름으로 미리 채워진 일반 구조체 값을 반환합니다. 모든 필수 필드의 경우 잘못된 자리 표시자 QVariant 가 삽입됩니다.

QOpcUaGenericStructHandler::DataTypeKind QOpcUaGenericStructHandler::dataTypeKindForTypeId(const QString &id) const

타입 노드 ID id 에 대한 데이터 타입 종류를 반환합니다.

std::optional<QOpcUaGenericStructValue> QOpcUaGenericStructHandler::decode(const QOpcUaExtensionObject &extensionObject) const

extensionObjectQOpcUaGenericStructValue 로 디코딩합니다. 디코더가 실패하면 std::nullopt 이 반환됩니다.

std::optional<QOpcUaExtensionObject> QOpcUaGenericStructHandler::encode(const QOpcUaGenericStructValue &value)

QOpcUaExtensionObject 로 인코딩된 value 또는 값을 인코딩할 수 없는 경우 std::nullopt 를 반환합니다.

QOpcUaEnumDefinition QOpcUaGenericStructHandler::enumDefinitionForTypeId(const QString &id) const

유형 노드 아이디 id 에 대해 QOpcUaEnumDefinition 를 반환합니다. 노드 ID를 알 수 없거나 열거형에 속하지 않는 경우 기본 구성 값이 반환됩니다.

bool QOpcUaGenericStructHandler::initialize()

데이터 타입 계층 구조 탐색을 시작합니다. 성공 또는 실패는 initializedChanged 신호로 보고됩니다.

작업을 시작할 수 없는 경우 false 을 반환합니다.

[since 6.7] bool QOpcUaGenericStructHandler::initialized() const

일반 구조체 핸들러가 초기화되면 true 를 반환합니다.

이 함수는 Qt 6.7에 도입되었습니다.

[signal] void QOpcUaGenericStructHandler::initializedChanged(bool initialized)

초기화 프로세스가 완료되면 이 신호가 전송됩니다. initialized 초기화에 성공했는지 여부를 나타냅니다.

bool QOpcUaGenericStructHandler::isAbstractTypeId(const QString &id) const

id 에서 설명하는 데이터 유형이 추상적인 경우 true를 반환합니다.

QOpcUaStructureDefinition QOpcUaGenericStructHandler::structureDefinitionForBinaryEncodingId(const QString &id) const

바이너리 인코딩 노드 아이디 id 에 대해 QOpcUaStructureDefinition 를 반환합니다. 노드 ID를 알 수 없거나 구조체 유형에 속하지 않으면 기본 생성된 값이 반환됩니다.

QOpcUaStructureDefinition QOpcUaGenericStructHandler::structureDefinitionForTypeId(const QString &id) const

유형 노드 아이디 id 에 대해 QOpcUaStructureDefinition 를 반환합니다. 노드 id를 알 수 없거나 구조체 유형에 속하지 않으면 기본 생성된 값이 반환됩니다.

QString QOpcUaGenericStructHandler::typeIdForBinaryEncodingId(const QString &id) const

바이너리 인코딩 아이디 id 와 연관된 타입 노드 아이디를 반환합니다.

QString QOpcUaGenericStructHandler::typeNameForBinaryEncodingId(const QString &id) const

바이너리 인코딩 노드 아이디 id 에 속하는 타입 이름을 반환합니다. 노드 ID를 알 수 없거나 구조체 유형에 속하지 않으면 빈 문자열이 반환됩니다.

QString QOpcUaGenericStructHandler::typeNameForTypeId(const QString &id) const

타입 노드 ID id 로 식별되는 데이터 타입 노드에 속하는 타입 이름을 반환합니다. 노드 ID를 알 수 없는 경우 빈 문자열이 반환됩니다.

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