QOpcUaClient Class

QOpcUaClient allows interaction with an OPC UA server. More...

Header: #include <QOpcUaClient>
qmake: QT += opcua
Inherits: QObject

Public Types

enum ClientError { NoError, InvalidUrl, AccessDenied, ConnectionError, UnknownError }
enum ClientState { Disconnected, Connecting, Connected, Closing }


  • error : const ClientError
  • state : const ClientState
  • 1 property inherited from QObject

Public Functions

QString backend() const
void connectToEndpoint(const QUrl &url)
void disconnectFromEndpoint()
ClientError error() const
QStringList namespaceArray() const
QOpcUaNode *node(const QString &nodeId)
ClientState state() const
bool updateNamespaceArray()
QUrl url() const
  • 32 public functions inherited from QObject


void connected()
void disconnected()
void errorChanged(QOpcUaClient::ClientError error)
void namespaceArrayUpdated(QStringList namespaces)
void stateChanged(QOpcUaClient::ClientState state)

Additional Inherited Members

  • 1 public slot inherited from QObject
  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

QOpcUaClient allows interaction with an OPC UA server.


QOpcUaClient implements basic client capabilities to communicate with OPC UA enabled devices and applications. This includes connecting, disconnecting and getting QOpcUaNode objects for a node on the server.

Addressing Nodes

For an introduction to nodes and node ids, see QOpcUaNode.


Create a QOpcUaClient using QOpcUaProvider and call connectToEndpoint() to connect to a server. After the connection is established, a QOpcUaNode object for the root node is requested.

QOpcUaProvider provider;
if (provider.availableBackends().isEmpty())
QOpcUaClient *client = provider.createClient(provider.availableBackends()[0]);
if (!client)
// Connect to the stateChanged signal. Compatible slots of QObjects can be used instead of a lambda.
QObject::connect(client, &QOpcUaClient::stateChanged, [client](QOpcUaClient::ClientState state) {
    qDebug() << "Client state changed:" << state;
    if (state == QOpcUaClient::ClientState::Connected) {
        QOpcUaNode *node = client->node("ns=0;i=84");
        if (node)
            qDebug() << "A node object has been created";
client->connectToEndpoint(QUrl("opc.tcp://")); // Connect the client to the server

Member Type Documentation

enum QOpcUaClient::ClientError

This enum type specifies the current error state of the client.

QOpcUaClient::NoError0No error occurred.
QOpcUaClient::InvalidUrl1The url to connect to has been wrongly specified or a connection to this url failed.
QOpcUaClient::AccessDenied2An attempt to connect to a server using username/password failed due to wrong credentials.
QOpcUaClient::ConnectionError3An error occurred with the connection.
QOpcUaClient::UnknownError4An unknown error occurred.

enum QOpcUaClient::ClientState

This enum type specifies the connection state of the client.

QOpcUaClient::Disconnected0The client is not connected to a server.
QOpcUaClient::Connecting1The client is currently connecting to a server.
QOpcUaClient::Connected2The client is connected to a server.
QOpcUaClient::Closing3The client has been connected and requests a disconnect from the server.

Property Documentation

error : const ClientError

Specifies the current error state of the client.

Access functions:

ClientError error() const

Notifier signal:

void errorChanged(QOpcUaClient::ClientError error)

state : const ClientState

Specifies the current connection state of the client.

Access functions:

ClientState state() const

Notifier signal:

void stateChanged(QOpcUaClient::ClientState state)

Member Function Documentation


Destroys the QOpcUaClient instance.

QString QOpcUaClient::backend() const

Returns the name of the backend used by this instance of QOpcUaClient, e.g. "open62541".

void QOpcUaClient::connectToEndpoint(const QUrl &url)

Connects to the OPC UA endpoint given in url.

See also disconnectFromEndpoint().

[signal] void QOpcUaClient::connected()

This signal is emitted when a connection has been established.

void QOpcUaClient::disconnectFromEndpoint()

Disconnects from the server.

See also connectToEndpoint().

[signal] void QOpcUaClient::disconnected()

This signal is emitted when a connection has been closed following to a close request.

ClientError QOpcUaClient::error() const

Returns the current error state of the client.

Note: Getter function for property error.

QStringList QOpcUaClient::namespaceArray() const

Returns the cached value of the namespace array.

The value is only valid after the namespaceArrayUpdated() signal has been emitted.

See also updateNamespaceArray() and namespaceArrayUpdated().

[signal] void QOpcUaClient::namespaceArrayUpdated(QStringList namespaces)

This signal is emitted after an updateNamespaceArray operation has finished. namespaces contains the content of the server's namespace table. The index of an entry in namespaces corresponds to the namespace index used in the node id.

QOpcUaNode *QOpcUaClient::node(const QString &nodeId)

Returns a QOpcUaNode object associated with the OPC UA node identified by nodeId. The caller becomes owner of the node object.

If the client is not connected, nullptr is returned. The backends may also return nullptr for other error cases (for example for a malformed node id).

bool QOpcUaClient::updateNamespaceArray()

Requests an update of the namespace array from the server. Returns true if the operation has been successfully dispatched.

The namespaceArrayUpdated() signal is emitted after the operation is finished.

See also namespaceArray() and namespaceArrayUpdated().

QUrl QOpcUaClient::url() const

Returns the URL of the OPC UA server the client is currently connected to or was last connected to.

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