ServerDiscovery QML Type
提供有关可用服务器的信息。更多...
| Import Statement: | import QtOpcUa |
| Since: | QtOpcUa 5.13 |
| Status: | Deprecated since 6.9 |
自 QtOpcUa 6.9 起,此类型已弃用。我们强烈建议不要在新代码中使用它。
属性
- connection : Connection
- count : int
- discoveryUrl : string
- status : Status
信号
方法
- 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
用于请求信息的连接。
如果未设置此属性,则将使用默认连接(如有)。
另请参阅 Connection 和Connection::defaultConnection 。
count : int
该元素中当前的服务器数量。在使用此服务器发现功能中的任何数据之前,您应访问status 以确认信息检索是否成功。
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 、count 以及Status 。
status : Status
该元素的当前状态。如果上次服务器检索成功,则状态应为Status.Good 。
if (status.isGood) {
// Choose endpoint to connect to
} else {
// handle error
}另请参阅 Status 。
Signal 文档
serversChanged()
当检索请求开始、完成或失败时触发。在被调用的函数中,应首先获取对象的status 。如果状态为Status.GoodCompletesAsynchronously ,则请求仍在运行中。如果状态为Status.Good ,则请求已完成,可以读取应用程序描述。如果状态不正常,则表示发生了错误,此时status 中包含返回的错误代码。
onServersChanged: {
if (status.isGood) {
if (status.status == QtOpcUa.Status.GoodCompletesAsynchronusly)
return; // wait until finished
if (count > 0) {
var serverUrl = at(0).endpointUrl();
console.log(serverUrl);
}
} else {
// handle error
}
}注意: 相应的处理程序 为onServersChanged 。
另请参阅 status 、count 、at 、Status 以及ApplicationDescription 。
方法文档
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.