<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QOpcUa crashes when remote device goes offline during read]]></title><description><![CDATA[<p dir="auto">I have a quite large application that read/write values from PLCs using QOpcUa.<br />
It works fine, but after running for several hours I get a crash of the application. Using the debugger, it stops at line 42096 of open62541.c:</p>
<pre><code>    if(client-&gt;channel.state != UA_SECURECHANNELSTATE_OPEN) {
        UA_LOG_INFO(&amp;client-&gt;config.logger, UA_LOGCATEGORY_CLIENT,
                    "SecureChannel must be connected before sending requests");
		return UA_STATUSCODE_BADSERVERNOTCONNECTED;
    }
</code></pre>
<p dir="auto">It crashes because <code>client</code> is <code>nullptr</code> (aka 0x00).  I'm quite puzzled that there is no check of the pointer. And of course I cannot change their code.</p>
<p dir="auto">I inspected the call stack, and if I'm not wrong it happened when I was trying to read an attribute using the async function <code>readValueAttribute()</code>.</p>
<p dir="auto">It's hard to tell, but my wild guess is the remote device went offline while executing the reading. And this may happen all the time.<br />
Here my function:</p>
<pre><code>void MyOpcUa::readAll()
{
    QMapIterator&lt;QString, Node_t&gt; i(_mapOpcNodes);
    while (i.hasNext())
    {
        i.next();
        Node_t node = i.value();
        if (node.enableRead)
        {
            node.updated = false;
            node.node-&gt;readValueAttribute();
        }
    }
}
</code></pre>
<p dir="auto"><code>_mapOpcNodes</code> contains the nodes to be read.<br />
This function is executed for each instance of my class, one for each PLC.</p>
<p dir="auto">Here how I add a node to the map:</p>
<pre><code>void MyOpcUa::insertNode(QString key, QString id, bool enableRead)
{
    Node_t node;
    node.node = _opcUaClient-&gt;node(id);
    node.value = QVariant();
    node.updated = false;
    node.enableRead = enableRead;
    _mapOpcNodes.insert(key, node);
    connect(node.node, &amp;QOpcUaNode::attributeRead, this, &amp;MyOpcUa::handleAttributes);
}
</code></pre>
<p dir="auto">How to improve my code to avoid such a crash when anything goes wrong between the <code>readValueAttribute()</code> call and the firing of the <code>attributeRead()</code> signal?</p>
]]></description><link>https://forum.qt.io/topic/145728/qopcua-crashes-when-remote-device-goes-offline-during-read</link><generator>RSS for Node</generator><lastBuildDate>Sat, 24 Oct 2026 12:56:14 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145728.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Jun 2023 18:47:18 GMT</pubDate><ttl>60</ttl></channel></rss>