이 페이지에서

Connection QML Type

서버에 연결합니다. 더 보기...

Import Statement: import QtOpcUa
Since: QtOpcUa 5.12
Status: Deprecated since 6.9

이 유형은 QtOpcUa 6.9부터 더 이상 사용되지 않습니다. 새로운 코드에서는 이 유형을 사용하지 않도록 강력히 권장합니다.

속성

신호

방법

상세 설명

메인 API는 백엔드를 사용하여 연결을 수행합니다. 연결을 시도하기 전에 반드시 백엔드를 설정해야 합니다.

import QtOpcUa as QtOpcUa

QtOpcUa.Connection {
    backend: "open62541"
}

Component.onCompleted: {
    connection.connectToEndpoint("opc.tcp://127.0.0.1:43344");
}

속성 설명서

authenticationInformation : AuthenticationInformation

이 연결에 대한 인증 정보를 설정합니다. 인증 정보는 ` connectToEndpoint`를 호출하기 전에 설정해야 합니다. 인증 정보가 설정되지 않은 경우 익명 모드가 사용됩니다. 이는 현재 연결에는 영향을 미치지 않습니다. 클라이언트가 연결이 끊어진 후 다시 연결되면 새로운 자격 증명이 사용됩니다. backend 가 설정되기 전에 이 속성을 읽거나 쓰면, 쓰기 작업은 무시되고 읽기 작업은 유효하지 않은 AuthenticationInformation 를 반환합니다.

availableBackends : stringlist [read-only]

사용 가능한 모든 백엔드의 이름을 리스트 형태로 반환합니다. 이 리스트는 연결 시 백엔드를 선택하는 데 사용됩니다.

Connection::backend도 참조하십시오 .

backend : string

서버에 연결할 때 사용할 백엔드를 설정합니다. 연결을 시도하기 전에 반드시 설정해야 합니다.

Connection::availableBackends도 참조하십시오 .

connected : bool [read-only]

연결 상태. 연결이 설정된 경우 true, 그렇지 않은 경우 false.

connection : QOpcUaClient

이 속성은 C++에서 연결을 주입하는 용도로만 사용됩니다. 연결 설정이 복잡한 경우 C++을 사용하여 모든 세부 사항을 처리할 수 있습니다. 연결이 설정된 후에는 이 속성을 사용하여 QML로 연결을 전달할 수 있습니다. 클라이언트의 소유권이 QML로 이전됩니다.

class MyClass : public QObject {
    Q_OBJECT
    Q_PROPERTY(QOpcUaClient* connection READ connection NOTIFY connectionChanged)

public:
    MyClass (QObject* parent = nullptr);
    QOpcUaClient *connection() const;

signals:
    void connectionChanged(QOpcUaClient *);

클라이언트 설정이 완료되면 ` connectionChanged ` 신호를 발산하면, 아래의 QML 코드가 해당 연결을 사용하게 됩니다.

import QtOpcUa as QtOpcUa

MyClass {
    id: myclass
}

QtOpcUa.Connection {
    connection: myclass.connection
 }

currentEndpoint : QOpcUaEndpointDescription

연결이 설정된 서버에 대한 엔드포인트 설명입니다. 연결이 설정되지 않은 경우, 빈 엔드포인트 설명이 반환됩니다.

defaultConnection : bool

이 연결을 기본 연결로 설정합니다. 일반적으로 각 노드에는 사용할 연결을 지정해야 합니다. 이 속성이 ` true`로 설정되면, 노드에 연결이 설정되어 있지 않은 모든 경우에 이 연결이 사용됩니다. 이미 설정된 연결에는 영향을 미치지 않습니다. ` defaultConnection `가 ` true `로 설정된 경우, 여러 연결이 있는 상태에서는 마지막 연결이 사용됩니다.

QtOpcUa.Connection {
    ...
    defaultConnection: true
    ...
}

Node도 참조하십시오 .

namespaces : stringlist [read-only]

연결된 서버에 등록된 모든 네임스페이스 URI의 문자열 목록.

supportedSecurityPolicies : stringlist

지원되는 보안 정책이 포함된 문자열 목록

이 속성은 현재 기술 미리보기(Technology Preview)로 제공되므로, 제공되는 API 및 기능은 사전 공지 없이 언제든지 변경될 수 있습니다.

supportedUserTokenTypes : array[tokenTypes]

지원되는 모든 사용자 토큰 유형에 대한 사용자 토큰 정책 유형의 배열입니다.

이 속성은 현재 기술 미리 보기(Technology Preview)로 제공되므로, 제공되는 API 및 기능은 사전 공지 없이 언제든지 변경될 수 있습니다.

Signal 문서

nodeChanged()

기본 노드가 변경되었을 때 발생합니다. 이는 NodeId 의 네임스페이스나 식별자가 변경되었을 때 발생합니다.

참고: 해당 핸들러는 onNodeChanged 입니다.

readNodeAttributesFinished(readResults)

readNodeAttributes()를 사용하여 시작된 읽기 요청이 완료되면 발생합니다. readResults 매개변수는 서버에서 요청한 값을 포함하는 ReadResult 항목들의 배열입니다.

connection.onReadNodeAttributesFinished(results) {
    for (var i = 0; results.length; i++) {
        if (results[i].status.isGood) {
            console.log(results[i].value);
        } else {
            // handle error
        }
    }
}

참고: 이에 대응하는핸들러는 onReadNodeAttributesFinished 입니다.

readNodeAttributes() 및 ReadResult도 참조하십시오 .

writeNodeAttributesFinished(writeResults)

writeNodeAttributes()를 사용하여 시작된 쓰기 요청이 완료되면 발생합니다. writeResults 매개변수는 서버에서 요청한 값을 포함하는 WriteResult 항목의 배열입니다.

for (var i = 0; i < writeResults.length; i++) {
    console.log(writeResults[i].nodeId);
    console.log(writeResults[i].namespaceName);
    console.log(writeResults[i].attribute);

    if (writeResults[i].status.isBad) {
        // value was not written
    }
}

참고: 이에 해당하는핸들러는 onWriteNodeAttributesFinished 입니다.

writeNodeAttributes() 및 WriteResult도 참조하십시오 .

메서드 문서

void connectToEndpoint(endpointDescription)

endpointDescription 로 지정된 엔드포인트에 연결합니다.

EndpointDescription도 참조하십시오 .

void disconnectFromEndpoint()

설정된 연결을 끊습니다.

bool readNodeAttributes(valuesToBeRead)

이 함수는 서버에서 여러 값을 한 번에 읽어오는 데 사용됩니다. 읽기 요청이 성공적으로 전송된 경우 ` true `를 반환합니다.

valuesToBeRead 매개변수는 ReadItem 항목으로 구성된 JavaScript 배열이어야 합니다.

// List of items to read
var readItemList = [];
// Item to be added to the list of items to be read
var readItem;

// Prepare an item to be read

// Create a new read item and fill properties
readItem = QtOpcUa.ReadItem.create();
readItem.ns = "http://qt-project.org";
readItem.nodeId = "s=Demo.Static.Scalar.Double";
readItem.attribute = QtOpcUa.Constants.NodeAttribute.DisplayName;

// Add the prepared item to the list of items to be read
readItemList.push(readItem);

// Add further items
[...]

if (!connection.readNodeAttributes(readItemList)) {
    // handle error
}

읽기 요청의 결과는 readNodeAttributesFinished() 시그널을 통해 제공됩니다.

readNodeAttributesFinished() 및 ReadItem도 참조하십시오 .

bool writeNodeAttributes(valuesToBeWritten)

이 함수는 여러 값을 한 번에 서버에 기록하는 데 사용됩니다. 쓰기 요청이 성공적으로 전송된 경우 ` true `를 반환합니다.

valuesToBeWritten 매개변수는 WriteItem 항목으로 구성된 JavaScript 배열이어야 합니다.

// List of items to write
var writeItemList = [];
// Item to be added to the list of items to be written
var writeItem;

// Prepare an item to be written

// Create a new write item and fill properties
writeItem = QtOpcUa.WriteItem.create();
writeItem.ns = "http://qt-project.org";
writeItem.nodeId = "s=Demo.Static.Scalar.Double";
writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
writeItem.value = 32.1;
writeItem.valueType = QtOpcUa.Constants.Double;

// Add the prepared item to the list of items to be written
writeItemList.push(writeItem);

// Add further items
[...]

if (!connection.writeNodeAttributes(writeItemList)) {
    // handle error
}

쓰기 요청의 결과는 Connection::writeNodeAttributesFinished() 시그널을 통해 제공됩니다.

Connection::writeNodeAttributesFinished() 및 WriteItem도 참조하십시오 .

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