このページでは

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 に設定すると、ノードに接続が設定されていない場合はすべて、この接続が使用されます。すでに確立されている接続は影響を受けません。複数の接続でdefaultConnectiontrue に設定すると、最後の接続が使用されます。

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

Nodeも参照してください

namespaces : stringlist [read-only]

接続されているサーバーに登録されているすべての名前空間URIの文字列のリスト。

supportedSecurityPolicies : stringlist

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

このプロパティは、現在、技術プレビューとして利用可能です。したがって、提供されるAPIと機能は、事前の通知なしにいつでも変更される可能性があります。

supportedUserTokenTypes : array[tokenTypes]

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

このプロパティは、現在、技術プレビューとして利用可能です。したがって、提供されるAPIと機能は、事前の通知なしにいつでも変更される可能性があります。

シグナル・ドキュメント

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.