From ed9025f03aa6fcbf720f4e022f3594c85de0a385 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 1 Apr 2026 11:54:12 +0200 Subject: Check all unchecked return values and guard error paths --- src/OpcUaMonitoredNode.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/OpcUaMonitoredNode.cpp') diff --git a/src/OpcUaMonitoredNode.cpp b/src/OpcUaMonitoredNode.cpp index beec934..1c125fc 100644 --- a/src/OpcUaMonitoredNode.cpp +++ b/src/OpcUaMonitoredNode.cpp @@ -132,7 +132,7 @@ OpcUaMonitoredNode::setupNode () return; auto *client = OpcUaClient::instance (); - if (!client || !client->connected ()) + if (!client || !client->connected () || !client->opcuaClient ()) return; m_node = client->opcuaClient ()->node (m_nodeId); @@ -152,12 +152,14 @@ OpcUaMonitoredNode::setupNode () connect (m_node, &QOpcUaNode::disableMonitoringFinished, this, &OpcUaMonitoredNode::handleDisableMonitoringFinished); - m_node->readAttributes ( - QOpcUa::NodeAttribute::DisplayName | QOpcUa::NodeAttribute::Description - | QOpcUa::NodeAttribute::NodeClass | QOpcUa::NodeAttribute::DataType - | QOpcUa::NodeAttribute::ValueRank - | QOpcUa::NodeAttribute::ArrayDimensions - | QOpcUa::NodeAttribute::AccessLevel); + if (!m_node->readAttributes (QOpcUa::NodeAttribute::DisplayName + | QOpcUa::NodeAttribute::Description + | QOpcUa::NodeAttribute::NodeClass + | QOpcUa::NodeAttribute::DataType + | QOpcUa::NodeAttribute::ValueRank + | QOpcUa::NodeAttribute::ArrayDimensions + | QOpcUa::NodeAttribute::AccessLevel)) + qWarning () << "OpcUaMonitoredNode: readAttributes failed for" << m_nodeId; if (m_monitored) startMonitoring (); @@ -195,7 +197,10 @@ OpcUaMonitoredNode::startMonitoring () if (!m_node || !m_monitored) return; QOpcUaMonitoringParameters params (m_publishingInterval); - m_node->enableMonitoring (QOpcUa::NodeAttribute::Value, params); + if (!m_node->enableMonitoring (QOpcUa::NodeAttribute::Value, params)) + qWarning () + << "OpcUaMonitoredNode: enableMonitoring failed to dispatch for" + << m_nodeId; } void @@ -203,7 +208,10 @@ OpcUaMonitoredNode::stopMonitoring () { if (!m_node) return; - m_node->disableMonitoring (QOpcUa::NodeAttribute::Value); + if (!m_node->disableMonitoring (QOpcUa::NodeAttribute::Value)) + qWarning () + << "OpcUaMonitoredNode: disableMonitoring failed to dispatch for" + << m_nodeId; } /* ====================================== -- cgit v1.2.3