aboutsummaryrefslogtreecommitdiffstats
path: root/src/OpcUaMonitoredNode.cpp
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-24 16:14:11 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-24 16:14:11 +0100
commit6816fc573608cf9a5783caeabd47b8dbe1ac5ac5 (patch)
tree495163282f951b7641c24c937eae2d0053ee1c49 /src/OpcUaMonitoredNode.cpp
parent5ff9705937ffc1647587e1b228effd30c8a0e309 (diff)
downloadBobinkQtOpcUa-6816fc573608cf9a5783caeabd47b8dbe1ac5ac5.tar.gz
BobinkQtOpcUa-6816fc573608cf9a5783caeabd47b8dbe1ac5ac5.zip
Suppress duplicate valueChanged after writeValue
Add m_pendingWrite flag to skip the write-path valueAttributeUpdated emission and let only the monitored item deliver the authoritative server value. Mirrors the existing m_pendingRangeWrite pattern.
Diffstat (limited to 'src/OpcUaMonitoredNode.cpp')
-rw-r--r--src/OpcUaMonitoredNode.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/OpcUaMonitoredNode.cpp b/src/OpcUaMonitoredNode.cpp
index 290a1c2..beec934 100644
--- a/src/OpcUaMonitoredNode.cpp
+++ b/src/OpcUaMonitoredNode.cpp
@@ -179,6 +179,7 @@ OpcUaMonitoredNode::teardownNode ()
emit infoChanged ();
m_valueType = QOpcUa::Types::Undefined;
+ m_pendingWrite = false;
m_pendingRangeWrite = false;
if (m_writable)
@@ -312,11 +313,14 @@ OpcUaMonitoredNode::handleAttributeUpdated (QOpcUa::NodeAttribute attr,
void
OpcUaMonitoredNode::handleValueUpdated (const QVariant &value)
{
- // After a range write, Qt emits valueAttributeUpdated with only the
- // partial written value instead of the full array. Ignore this
- // update and let the monitored item deliver the correct full array
- // on the next data change notification.
- if (m_pendingRangeWrite)
+ // After a write, Qt emits valueAttributeUpdated from the write path
+ // before the server's monitored item notification arrives. For regular
+ // writes this is a duplicate; for range writes it carries only the
+ // partial written value. Ignore both and let monitoring deliver the
+ // authoritative value. Removing this guard would give an immediate UI
+ // update that does not reflect the actual server state, which could be
+ // useful for optimistic updates.
+ if (m_pendingWrite || m_pendingRangeWrite)
return;
// Store the new value pushed by the OPC UA monitored item.
@@ -357,6 +361,7 @@ OpcUaMonitoredNode::handleAttributeWritten (QOpcUa::NodeAttribute attr,
if (attr != QOpcUa::NodeAttribute::Value)
return;
+ m_pendingWrite = false;
m_pendingRangeWrite = false;
bool ok = (statusCode == QOpcUa::Good);
@@ -560,9 +565,13 @@ OpcUaMonitoredNode::writeValue (const QVariant &value)
return;
}
+ m_pendingWrite = true;
if (!m_node->writeValueAttribute (coerced, m_valueType))
- emit writeCompleted (false,
- QStringLiteral ("Write request failed to dispatch"));
+ {
+ m_pendingWrite = false;
+ emit writeCompleted (
+ false, QStringLiteral ("Write request failed to dispatch"));
+ }
}
void