Solved SIGNAL argument
-
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 problemvoid 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
-
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);