Pass QXmlStreamReader Instance to Class
I am trying to read an XML document using QXmlStreamReader. I am running into issues when I try to pass a pointer to the reader to other classes. I create an instance of the reader in one class. That class reads the XML until it comes to a block defining a new class. I create and instance of the new class and then call a function in that class to continue reading the XML specific for it. For instance:
Q_ASSERT(XML.isStartElement() && XML.name() == MODES);
NumModes = XML.attributes().value(COUNT).toInt();
if (XML.name() == MODE)
ModeClass* pMode = new ModeClass(this);
ModeList += XML.attributes().value(ID).toString();
XML.raiseError(QObject::tr("Something other than Mode block encountered in Modes block"));
This works part way through the file but then the reader seems to forget what level its at. readNextStartElement() returns false when it shouldn't. The file is fine as I took a TreeWidget example and customized it for my use and it reads the whole file just fine. I am thinking that for some reason I cannot pass a pointer to the reader to another classes function to continue reading the XML?
You can pass. We use everywhere. You can pass. Some of the sample methods we have are
@ void readCompanyNew(QXmlStreamReader *par);
void readProjectNew(QXmlStreamReader *par);
I am calling them like
Thanks, that is good to know. I will keep digging into this then.
if you want the complete sample, drop email to me. I will send you the complete solution dump.
Thanks but I think its in my code somewhere but I am missing it. I am finding it hard to debug because I don't know why readNextStartElement() is returning a false where it should not. Here is a sample of my XML. My code reads all the <Channel> blocks fine. It then it reads the <Servos> start element and the first <Servo> block fine but then gets a false from readNextStartElement() when it should read the next <Servo> start element and goes all the way back up to my Mode loop. Just need to figure out why it does not read the second servo block. Thanks.
@<?xml version="1.0" encoding="UTF-8"?>
OK, solved. My inexperience in dealing with the XML reader. I missed a case in my switch statement which caused an item to be missed and put things out of sequence. I need to add a default with a skipCurrentElement or raise an error. Thanks for all the feedback, it helped me catch this.