En esta página

ServerDiscovery QML Type

Proporciona información sobre los servidores disponibles. Más...

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

Este tipo está obsoleto desde QtOpcUa 6.9. Recomendamos encarecidamente no utilizarlo en código nuevo.

Propiedades

Señales

Métodos

  • ApplicationDescription at(index)

Descripción detallada

Permite obtener y acceder a información sobre los servidores conocidos por un servidor o un servidor de descubrimiento.

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);
        }
    }
}

Documentación de propiedades

connection : Connection

La conexión que se utilizará para solicitar información.

Si no se configura esta propiedad, se utilizará la conexión predeterminada, si la hay.

Véase también Connection y Connection::defaultConnection.

count : int

Número actual de servidores en este elemento. Antes de utilizar cualquier dato de esta detección de servidores, debes consultar status para comprobar si la obtención de la información se ha realizado correctamente.

Véase también status y Status.

discoveryUrl : string

URL del servidor desde el que se va a recuperar la lista de servidores. Cada vez que se modifica la URL, se inicia una solicitud al servidor indicado.

Al iniciar la solicitud, se borra la lista de servidores disponibles y el estado se establece en « Status.GoodCompletesAsynchronously ». Una vez finalizada la solicitud, el estado cambia a « status ». Asegúrate de comprobar el estado « status » antes de acceder a la lista de servidores.

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
        }
}

Véase también ApplicationDescription, status, at, count y Status.

status : Status

El estado actual de este elemento. Si la última consulta de servidores se ha realizado con éxito, el estado debería ser « Status.Good ».

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

Véase también Status.

Documentación de Signal

serversChanged()

Se emite cuando una solicitud de recuperación se inicia, finaliza o falla. En una función llamada, primero debes consultar el método ` status ` del objeto. Si el estado es ` Status.GoodCompletesAsynchronously`, la solicitud sigue en curso. Si el estado es ` Status.Good`, la solicitud ha finalizado y se pueden leer las descripciones de la aplicación. Si el estado no es correcto, se ha producido un error y ` status ` contiene el código de error devuelto.

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
        }
}

Nota: El controlador correspondiente es onServersChanged.

Véase también status, count, at, Status y ApplicationDescription.

Documentación del método

ApplicationDescription at(index)

Devuelve la descripción de la aplicación en la dirección index indicada. En caso de que no haya servidores disponibles o el índice no sea válido, se devuelve una descripción de aplicación no válida. Antes de utilizar cualquier dato devuelto, debes comprobar en status si la recuperación de la información se ha realizado correctamente.

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

Véase también count, status y 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.