diff options
author | Jannis Voelker <jannis.voelker@basyskom.com> | 2018-04-03 11:00:43 +0200 |
---|---|---|
committer | Frank Meerkoetter <frank.meerkoetter@basyskom.com> | 2018-04-05 18:44:26 +0000 |
commit | 2d505d5f5a55c4bdfe316c69986d00cc149d98b9 (patch) | |
tree | ed0aeef58911ace14f317fad1cba161f1ae83493 | |
parent | 9fc143f3c6a1530ec20cdc19d4e28658ac7b0033 (diff) |
Fix client state handler in the qml example
clientStateHandler must be connected to the stateChanged signal only
once. Failing to do so creates an additional connection for each connect
which leads to the creation of useless nodes.
Change-Id: I2f5ee1dbf1697722dfca3762551bfae80412fdae
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
-rw-r--r-- | examples/opcua/waterpump/qml-hmi/opcuamachinebackend.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/examples/opcua/waterpump/qml-hmi/opcuamachinebackend.cpp b/examples/opcua/waterpump/qml-hmi/opcuamachinebackend.cpp index 6238c89..ab1da00 100644 --- a/examples/opcua/waterpump/qml-hmi/opcuamachinebackend.cpp +++ b/examples/opcua/waterpump/qml-hmi/opcuamachinebackend.cpp @@ -322,8 +322,11 @@ void OpcUaMachineBackend::connectToEndpoint(const QString &url, qint32 index) if (index < 0 || index >= m_backends.size()) return; // Invalid index - if (!m_client || (m_client && m_client->backend() != m_backends.at(index))) + if (!m_client || (m_client && m_client->backend() != m_backends.at(index))) { m_client.reset(provider.createClient(m_backends.at(index))); + if (m_client) + QObject::connect(m_client.data(), &QOpcUaClient::stateChanged, this, &OpcUaMachineBackend::clientStateHandler); + } if (!m_client) { qWarning() << "Could not create client"; @@ -332,7 +335,6 @@ void OpcUaMachineBackend::connectToEndpoint(const QString &url, qint32 index) } m_successfullyCreated = true; - QObject::connect(m_client.data(), &QOpcUaClient::stateChanged, this, &OpcUaMachineBackend::clientStateHandler); m_client->connectToEndpoint(QUrl(url)); } |