Reputation: 1513
I have a QXmlStreamReader variable and I want it to go over my xml file- QFile, and read all the start elements by the function readNextStartElement(). But it gives me every start tag twice.
Here is my code:
QXmlStreamReader* xmlReader = new QXmlStreamReader(orFile);
xmlReader->readNextStartElement();
std::string tagName = (orXmlReader->name()).toLocal8Bit().constData();
cout << tagName;
xmlReader->readNextStartElement();
tagName = (orXmlReader->name()).toLocal8Bit().constData();
cout << tagName;
Can someone help me find a solution? I there another function that can read normally the start elements?
Upvotes: 0
Views: 1438
Reputation: 25165
That API is confusing indeed and the documentation doesn’t help much for this particular case.
I think two things are worth mentioning:
false
without changing the position. Only the next call moves the position (and returns true
in the good case).So in our example, you can either actually read the content of the tag, or check the return value of readNextStartElement() and ignore it when it returns false
. That might then ignore some valid error cases though.
Upvotes: 1