Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved SIGNAL argument

    General and Desktop
    1
    2
    153
    Loading More Posts
    • 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.
    • ODБOï
      ODБOï last edited by ODБOï

      Hi,

      I'm trying to create c++ method to refactor my OPC UA subscription creation code.

      ...
      privete :
             QScopedPointer<QOpcUaNode> nIndexNode; // node on the server is  "ns=4;s=MAIN.nIndex"
      signals: 
           nIndexChanged();
      ...
      // i want to make  following code more generic because i have more than 50 subscriptions
      ...
             nIndexNode.reset(m_client->node("ns=4;s=MAIN.nIndex"));      
             QObject::connect(node.data(),&QOpcUaNode::attributeUpdated,this,&MachineBackend::nIndexUpdated);
      
      

      i want to create a method that takes
      -a referenceon the private node pointer ( nIndexNode)
      -a QString that represents the node id on the server (ns=4;s=MAIN.nIndex)
      -something that allows me to call/emit the suited SIGNAL, here is my problem

        void uaSub(QScopedPointer<QOpcUaNode> &node, QString nodeId, /* the signal to be called */){
      
              node.reset(m_client->node(nodeId)); 
                    QObject::connect(nIndexNode.data(),&QOpcUaNode::attributeUpdated,this,&/*MachineBackend::nIndexUpdated*/); // how to get the Signal name  ? 
          }
      

      then i could simply call it

      uaSub(nIndexNode,"ns=4;s=MAIN.nIndex",&MachineBackend::nIndexChanged)
      uaSub(temperNode,"ns=4;s=MAIN.temperValue",&MachineBackend::temperChanged)
      ...
      

      thank you in advance

      ODБOï 1 Reply Last reply Reply Quote 0
      • ODБOï
        ODБOï @ODБOï last edited by ODБOï

        i managed to solve this by myself

        // nIndex update handler
           static void nIndexUpdated(QOpcUa::NodeAttribute attr, const QVariant &value){
                qDebug()<< "new value is  " << value;
            }
        
            void uaSub(QScopedPointer<QOpcUaNode> &node, QString nodeId , void (*theUpdateHandler)(QOpcUa::NodeAttribute attr,const QVariant &value)){
                node.reset(m_client->node(nodeId));
        
                QObject::connect(node.data(),&QOpcUaNode::attributeUpdated,[=](QOpcUa::NodeAttribute attr,const QVariant &value){
                    theUpdateHandler(attr,value);
                });
            }
        

        use

          uaSub(nIndexNode,"ns=4;s=MAIN.nIndex",nIndexUpdated);
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post