QOpcUaGenericStructHandler Class
서버의 데이터 유형을 읽고, 일반 구조체를 확장 객체로 변환하거나 그 반대로 변환합니다. 더 보기...
| 헤더: | #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 ` 값이 존재하는 구조화된 유형의 경우, 이를 포함하는 확장 객체를 자동으로 디시리얼라이즈할 수 있습니다. 내장형(built-in type)이거나 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
이 열거형 유형은 데이터 유형 노드의 데이터 유형 종류를 지정합니다.
| 상수 | 값 | 설명 |
|---|---|---|
QOpcUaGenericStructHandler::DataTypeKind::Unknown | 0 | 유형 노드 ID가 알 수 없습니다. |
QOpcUaGenericStructHandler::DataTypeKind::Struct | 1 | 유형 노드 ID가 구조화된 유형에 속합니다. |
QOpcUaGenericStructHandler::DataTypeKind::Enum | 2 | 이 타입 노드 ID는 열거형(enum)에 속합니다. |
QOpcUaGenericStructHandler::DataTypeKind::Other | 3 | 이 타입 노드 ID는 구조체(struct)나 열거형(enum)이 아닌 타입(기타 내장 타입 또는 그 하위 타입)에 속합니다. |
멤버 함수 문서
[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 를 알려진 유형에 추가합니다. 이는 서버에서 StructureDefinition을 노출하지 않는 사용자 정의 구조체를 지원하기 위해 사용할 수 있습니다. 올바른 디코딩 및 인코딩을 위해서는 definition, typeId 및 name 매개변수가 필수입니다. isAbstract 가 설정된 경우, 해당 유형은 인코딩 및 디코딩될 수 없습니다.
열거형 정의가 성공적으로 추가된 경우 ` true `를 반환합니다.
bool QOpcUaGenericStructHandler::addCustomStructureDefinition(const QOpcUaStructureDefinition &definition, const QString &typeId, const QString &name, QOpcUa::IsAbstract isAbstract = QOpcUa::IsAbstract::NotAbstract)
사용자 정의 구조체 정의 definition 를 알려진 유형에 추가합니다. 이 기능은 서버에서 StructureDefinition을 제공하지 않는 사용자 정의 구조체를 지원하기 위해 사용할 수 있습니다. 올바른 디코딩 및 인코딩을 위해서는 definition, typeId 및 name 매개변수가 필수입니다. 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
extensionObject 를 QOpcUaGenericStructValue 로 디코딩합니다. 디코딩에 실패하면 std::nullopt 가 반환됩니다.
std::optional<QOpcUaExtensionObject> QOpcUaGenericStructHandler::encode(const QOpcUaGenericStructValue &value)
QOpcUaExtensionObject 으로 인코딩된 value 를 반환하거나, 값을 인코딩할 수 없는 경우 std::nullopt 를 반환합니다.
QOpcUaEnumDefinition QOpcUaGenericStructHandler::enumDefinitionForTypeId(const QString &id) const
id 의 노드 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 id 에 대한 ` QOpcUaStructureDefinition `를 반환합니다. 노드 ID를 알 수 없거나 구조체 유형에 속하지 않는 경우, 기본 생성된 값이 반환됩니다.
QOpcUaStructureDefinition QOpcUaGenericStructHandler::structureDefinitionForTypeId(const QString &id) const
id 의 노드 ID에 해당하는 타입의 ` QOpcUaStructureDefinition `를 반환합니다. 노드 ID가 알려지지 않았거나 구조체 타입에 속하지 않는 경우, 기본 생성된 값이 반환됩니다.
QString QOpcUaGenericStructHandler::typeIdForBinaryEncodingId(const QString &id) const
id 라는 이진 인코딩 ID와 연관된 타입 노드 ID를 반환합니다.
QString QOpcUaGenericStructHandler::typeNameForBinaryEncodingId(const QString &id) const
id 라는 바이너리 인코딩 노드 ID에 해당하는 유형 이름을 반환합니다. 노드 ID가 알려지지 않았거나 구조체 유형에 속하지 않는 경우, 빈 문자열이 반환됩니다.
QString QOpcUaGenericStructHandler::typeNameForTypeId(const QString &id) const
type 노드 ID id 로 식별되는 데이터 유형 노드에 해당하는 유형 이름을 반환합니다. 노드 ID를 알 수 없는 경우, 빈 문자열이 반환됩니다.
© 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.