在本页

ServerDiscovery QML Type

提供有关可用服务器的信息。更多

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

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

属性

方法

  • ApplicationDescription 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

用于请求信息的连接。

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

另请参阅 ConnectionConnection::defaultConnection

count : int

该元素中服务器的当前数量。在使用该服务器发现中的任何数据之前,应检查status 是否成功检索到信息。

另请参阅 statusStatus

discoveryUrl : string

用于获取服务器列表的服务器 URL。每次更改 URL 时,都会向指定服务器发出请求。

启动请求时,可用服务器列表会被清空,状态被设置为Status.GoodCompletesAsynchronously 。请求完成后,status 。访问服务器列表前,请务必检查status

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

另请参阅 ApplicationDescription,status,at,countStatus

status : Status

该元素的当前状态。如果上次服务器检索成功,则状态应为Status.Good

if (status.isGood) {
    // Choose endpoint to connect to
} else {
    // handle error
}

另请参见 Status

方法文档

ApplicationDescription at(index)

返回给定index 中的应用程序说明。如果没有可用的服务器或索引无效,则返回无效的应用程序说明。在使用任何返回的数据之前,应检查status 是否成功检索到信息。

if (servers.status.isGood) {
    if (servers.count > 0)
        var serverUrl = at(0).serverUrl();
        console.log(serverUrl);
        // Choose endpoint to connect to
} else {
    // handle error
}

另请参阅 count,status, 和ApplicationDescription

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