View Full Version : Cannot read second XML element

23rd June 2017, 01:02
The question is:

I have the following XML file which I believe is valid XML:

<?xml version="1.0" encoding="UTF-8"?>

and have the following code to read it:

QString settingsFile = settingsDir + "/QBoardSettings.xml";
QFile file(settingsFile);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlStreamReader xmlStreamReader(&file);
while (xmlStreamReader.readNextStartElement()) {
QString s = xmlStreamReader.name().toString();

But this code prints only "Style" instead of printing names for both elements. What I am doing wrong? Thanks in advance.

23rd June 2017, 13:10
Just found answer - should have been using atEnd() and readNext().

24th June 2017, 04:24
Glad you got it working, but I believe the XML standards state that a valid XML document should be contained in a root element. In your example, something like the following where "Game" is the root element:

<?xml version="1.0" encoding="UTF-8"?>