Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpcUa crashes when remote device goes offline during read
Qt 6.12 LTS is out! See what's new in the release blog

QOpcUa crashes when remote device goes offline during read

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 237 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I have a quite large application that read/write values from PLCs using QOpcUa.
    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:

        if(client->channel.state != UA_SECURECHANNELSTATE_OPEN) {
            UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
                        "SecureChannel must be connected before sending requests");
    		return UA_STATUSCODE_BADSERVERNOTCONNECTED;
        }
    

    It crashes because client is nullptr (aka 0x00). I'm quite puzzled that there is no check of the pointer. And of course I cannot change their code.

    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 readValueAttribute().

    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.
    Here my function:

    void MyOpcUa::readAll()
    {
        QMapIterator<QString, Node_t> i(_mapOpcNodes);
        while (i.hasNext())
        {
            i.next();
            Node_t node = i.value();
            if (node.enableRead)
            {
                node.updated = false;
                node.node->readValueAttribute();
            }
        }
    }
    

    _mapOpcNodes contains the nodes to be read.
    This function is executed for each instance of my class, one for each PLC.

    Here how I add a node to the map:

    void MyOpcUa::insertNode(QString key, QString id, bool enableRead)
    {
        Node_t node;
        node.node = _opcUaClient->node(id);
        node.value = QVariant();
        node.updated = false;
        node.enableRead = enableRead;
        _mapOpcNodes.insert(key, node);
        connect(node.node, &QOpcUaNode::attributeRead, this, &MyOpcUa::handleAttributes);
    }
    

    How to improve my code to avoid such a crash when anything goes wrong between the readValueAttribute() call and the firing of the attributeRead() signal?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved