0

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?

  • Your debug code can't work. You are blocking the event loop with you while-loop. – Frank Meerkötter Oct 21 '19 at 14:20
  • Also for your original code, did you check the valueAttributeError? – Frank Meerkötter Oct 22 '19 at 06:33
  • Thanks for your reply! The ValueAttributeError returns QOpcUa::BadNoEntryExists as expectable, but how am I supposed to "wait" for the signal without a loop like this? – Clément Dewaele Oct 22 '19 at 07:24
  • I used this: https://stackoverflow.com/questions/31358646/qt5-how-to-wait-for-a-signal-in-a-thread in an adapted version and it works! valueAttributeError() is now Good and the reading value is correct. Thanks for your help – Clément Dewaele Oct 22 '19 at 07:34

0 Answers0