このページでは

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

サポートされているセキュリティポリシーを含む文字列の一覧

このプロパティは現在、テクノロジープレビューとして提供されているため、提供されるAPIおよび機能は、事前の予告なく随時変更される可能性があります。

supportedUserTokenTypes : array[tokenTypes]

サポートされているすべてのユーザートークンタイプに対応する、ユーザートークンポリシータイプの配列。

このプロパティは現在、テクノロジープレビューとして提供されているため、提供される 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.