本页内容

EndpointDiscovery QML Type

提供有关服务器上可用端点的信息。更多...

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

自 QtOpcUa 6.9 起,此类型已弃用。我们强烈建议不要在新代码中使用它。

属性

信号

方法

  • EndpointDescription at(index)

详细说明

允许获取并访问服务器上可用端点的相关信息。

QtOpcUa.Connection {
    id: connection
    backend: availableBackends[0]
    defaultConnection: true
}

QtOpcUa.ServerDiscovery {
    discoveryUrl: "opc.tcp://127.0.0.1:43344"
    onServersChanged: {
        if (status.isGood) {
            if (status.status == QtOpcUa.Status.GoodCompletesAsynchronusly)
                return; // wait until finished
            if (count > 0) {
                // choose right server
                endpointDiscovery.serverUrl = at(0).discoveryUrls[0];
                console.log("Using server URL:", endpointDiscovery.serverUrl);
            } else {
                // no servers retrieved
            }
        } else {
            // Fetching servers failed
            console.log("Error fetching server:", servers.status.status);
        }
    }
}

QtOpcUa.EndpointDiscovery {
    id: endpointDiscovery
    onEndpointsChanged: {
        if (status.isGood) {
            if (status.status == QtOpcUa.Status.GoodCompletesAsynchronusly)
                return; // wait until finished
            if (count > 0) {
                // choose right endpoint
                console.log("Using endpoint", at(0).endpointUrl, at(0).securityPolicy);
                connection.connectToEndpoint(at(0));
            } else {
                // no endpoints retrieved
            }
        } else {
            // Fetching endpoints failed
            console.log("Error fetching endpoints:", status.status);
        }
    }
}

属性文档

connection : Connection

用于请求信息的连接。

如果未设置此属性,则将使用默认连接(如有)。

另请参阅 Connection 和Connection::defaultConnection 。

count : int

该元素中当前的端点数量。在使用端点发现中的任何数据之前,应访问status 以确认信息是否已成功获取。

另请参阅 status 和Status 。

serverUrl : string

用于获取端点的服务器的发现 URL。每次更改该 URL 时,都会向指定服务器发起请求。

发起请求时,将清空可用端点列表,并将状态设置为Status.GoodCompletesAsynchronously 。请求完成后,status 会发生变化。

在访问端点列表之前,请务必先检查status 。

另请参阅 endpointsChanged 。

status : Status

该元素的当前状态。如果上次获取端点操作成功,则状态为Status.Good 。

if (endpoints.status.isGood) {
    // do something
} else {
    // handle error
}

另请参阅 Status 。

Signal 文档

endpointsChanged()

当检索请求开始、完成或失败时触发。在被调用的函数中,应首先检查对象的status 属性。如果状态为Status.GoodCompletesAsynchronously ,则请求仍在运行;如果状态为Status.Good ,则请求已完成,此时可以读取端点描述;如果状态不正常,则表示发生了错误,此时status 中包含返回的错误代码。

onEndpointsChanged: {
        if (endpoints.status.isGood) {
            if (endpoints.status.status == QtOpcua.Status.GoodCompletesAsynchronusly)
                return; // wait until finished
            if (endpoints.count > 0) {
                var endpointUrl = endpoints.at(0).endpointUrl();
                console.log(endpointUrl);
            }
        } else {
            // handle error
        }
}

注意: 对应的处理程序 为onEndpointsChanged 。

另请参阅 status 、count 、at 、Status 以及EndpointDescription 。

方法文档

EndpointDescription at(index)

返回指定index 处的端点描述。如果没有可用端点或索引无效,则返回一个无效的端点描述。在使用此处提供的任何数据之前,您应检查status 以确认信息检索是否成功。

if (endpoints.status.isGood) {
    if (endpoints.count > 0)
        var endpointUrl = endpoints.at(0).endpointUrl();
        console.log(endpointUrl);
} else {
    // handle error
}

另请参阅 count 、status 以及EndpointDescription 。

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