Solved QXmlStreamReader, readElementText method
-
Hello everyone,
This question might be more related to pure C++ than to Qt.While using QXmlStreamReader I've ran into a strange behavior.
Here is the code I had:QXmlStreamReader reader; reader.addData(data); while(reader.readNextStartElement()) { if (reader.name() == "api_url") { qDebug() << reader.readElementText(); //m_apiUrl is a QString private member variable m_apiUrl = reader.readElementText(); qDebug() << "m_apiUrl: " << m_apiUrl; } }
In this case the m_apiUrl variable value was set to an empty string.
But as soon as I've deleted the first qDebug statement m_apiUrl was set with a correct value.So I would like to know what happened and why.
Thank you for reading.
-
@Aymeric_Qt said in QXmlStreamReader, readElementText method:
So I would like to know what happened and why.
See the documentation - you read the element, so it's already read and the next call to readElementText() will not return anything.
-
@Aymeric_Qt said in QXmlStreamReader, readElementText method:
So I would like to know what happened and why.
See the documentation - you read the element, so it's already read and the next call to readElementText() will not return anything.
-
@Christian-Ehrlicher I missed that when I've read the documentation. Thank you!