Reputation: 3
I am writing a program in Qt and I use the QOpcUaNode class. To this point, I only had to write on the OPC using writeAttribute, and it worked fine (meaning my nodes are set up correctly as far as I can see). Now, I also need to read the info stored in the nodes, and I can't get it to work, always receiving a QVariant(Invalid) when I try to display the attribute using qDebug()
From what I read in the documentation, the signal attributeRead must be emitted before I can read a node. I tried two different things to get this signal emitted: readAttributes(QOpcUa::NodeAttribute::Value) and readValueAttribute() Here is my code, Flow being my QOpcUaNode* and m_custom being a bool member of my class and initially set to false:
connect(Flow, &QOpcUaNode::attributeRead, this, &OPC_Client::custom);
qDebug() << Flow->readValueAttribute();
qDebug() << Flow->readAttributes(QOpcUa::NodeAttribute::Value);
int i(0);
while (m_custom != true) {qDebug() << i; i++;}
custom is a slot simply doing m_custom = true; When I compile and start the program, once those lines are reached, the value of i goes up and never stops which means I suppose that the signal is never emitted. I first tried without the while loop, just reading the value without waiting and received a QVariant(Invalid)...
I write using Flow ->writeAttribute(QOpcUa::NodeAttribute::Value, true ,QOpcUa::Types::Boolean); and everything works fine.
Can someone help me with this please?
Upvotes: 0
Views: 156