In questa pagina

ServerDiscovery QML Type

Fornisce informazioni sui server disponibili. Altro...

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

Questo tipo è deprecato a partire da QtOpcUa 6.9. Si sconsiglia vivamente di utilizzarlo nel nuovo codice.

Proprietà

Segnali

Metodi

  • ApplicationDescription at(index)

Descrizione dettagliata

Consente di recuperare e accedere alle informazioni relative ai server noti a un server o a un server di rilevamento.

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

Documentazione delle proprietà

connection : Connection

La connessione da utilizzare per richiedere informazioni.

Se questa proprietà non è impostata, verrà utilizzata la connessione predefinita, se presente.

Vedi anche Connection e Connection::defaultConnection.

count : int

Numero attuale di server presenti in questo elemento. Prima di utilizzare qualsiasi dato ricavato da questa individuazione dei server, è necessario verificare su status se il recupero delle informazioni è andato a buon fine.

Vedi anche status e Status.

discoveryUrl : string

URL del server da cui recuperare l'elenco dei server. Ogni volta che l'URL viene modificato, viene avviata una richiesta al server specificato.

All'avvio della richiesta, l'elenco dei server disponibili viene azzerato e lo stato viene impostato su Status.GoodCompletesAsynchronously. Una volta terminata la richiesta, status cambia. Assicurati di controllare status prima di accedere all'elenco dei server.

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

Vedi anche ApplicationDescription, status, at, count e Status.

status : Status

Lo stato attuale di questo elemento. Se l'ultimo recupero dei server è andato a buon fine, lo stato dovrebbe essere " Status.Good".

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

Vedi anche Status.

Documentazione Signal

serversChanged()

Viene emesso quando una richiesta di recupero è stata avviata, completata o ha dato esito negativo. In una funzione chiamata, è necessario prima verificare il metodo ` status ` dell'oggetto. Se lo stato è ` Status.GoodCompletesAsynchronously`, la richiesta è ancora in corso. Se lo stato è ` Status.Good`, la richiesta è terminata ed è possibile leggere le descrizioni dell'applicazione. Se lo stato non è positivo, si è verificato un errore e ` status ` contiene il codice di errore restituito.

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: il gestore corrispondente è onServersChanged.

Vedi anche status, count, at, Status e ApplicationDescription.

Documentazione sui metodi

ApplicationDescription at(index)

Restituisce la descrizione dell'applicazione all'indirizzo specificato index. Qualora non fossero disponibili server o l'indice non fosse valido, viene restituita una descrizione dell'applicazione non valida. Prima di utilizzare i dati restituiti, è necessario verificare su status se il recupero delle informazioni è andato a buon fine.

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

Vedi anche count, status e 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.