Unsolved trying to use QXmlParser and friends
-
@Chris-Kawa oh my goodness, that is a thing of beauty.
Thanks to all who helped.
EDIT: actually, I do have a follow-on question: this will allow me to build my map of tags and content. I need to export that map when I'm done. I'm thinking of making the map a member variable, and adding a method that returns it. Is there a better way to do this?
-
I'm thinking of making the map a member variable, and adding a method that returns it. Is there a better way to do this?
So an XMLTagMapMakerHandler? Sounds good to me.
-
Well, I shouldn't have declared victory so quickly. When I migrated my test code into my app, I got this error:
C:\wifibutton\utility\xmlparser.h:16: error: 'XmlHandler' does not name a type; did you mean 'XmlParser'? XmlHandler m_handler; ^~~~~~~~~~ XmlParser
Here are some snippets:
class XmlHandler : public QXmlDefaultHandler { private: MsgHash m_hash; public: XmlHandler(); ... }
#include "xmlhandler.h" class XmlParser { QXmlSimpleReader m_reader; XmlHandler m_handler; ... }
Is there something special I need to know about sub-classing QXmlDefaultHandler, or am I just brain-fading here?
Thanks...
-
@mzimmers
Just to be sure its not that.
Does xmlparser.h include XmlHandler.h and reverse ?
(circular include) -
@mrjj no. xmlparser.h includes xmlhandler.h, but not the other way around.
-
@mzimmers
Ok, just had to be sure :)It simply says it don't know type so it don't see the include for some reason.
Did you try clean all, rebuild ?
-
Yes, I did.
Here's the complete code from the headers:
xmlhandler.h
#ifndef XMLHANDLER_H #define XMLHANDLER_H #include <QXmlDefaultHandler> #include "message.h" using namespace std; class XmlHandler : public QXmlDefaultHandler { private: MsgHash m_hash; bool m_tagStarted = false; QString m_tag; QString m_data; QXmlInputSource *m_source; public: XmlHandler(); ~XmlHandler(); bool startElement(const QString &uri, const QString &local, const QString &name, const QXmlAttributes &atts) override; bool endElement(const QString &uri, const QString &local, const QString &name) override; bool characters(const QString &ch) override; void getHash(MsgHash &msgHash) {msgHash = m_hash;} }; #endif // XMLHANDLER_H
xmlparser.h:
#ifndef XMLPARSER_H #define XMLPARSER_H #include <stdint.h> #include <QXmlDefaultHandler> #include <QXmlSimpleReader> #include "constants.h" #include "message.h" #include "xmlhandler.h" class XmlParser { QXmlSimpleReader m_reader; XmlHandler m_handler; public: XmlParser(); ~XmlParser(); int process(string xml, MsgHash &msgHash); }; #endif // XMLPARSER_H
-
Hi
It looks ok.
Could you try add some dummy class to the xmlhandler.hclass Test {
};and see if it can see that symbol ?
just to test it dont see the include and not something with class XmlHandler
-
@mrjj good test -- it didn't see that either. I wonder if XMLHANDLER_H is a reserved term...?
ANSWER: no it isn't...
-
Hmm can you check your .pro file its not listed 2 times ?
Also
can you please inspect both files
with Include Hierarchy?
The last.and see if you see anything odd.
-
@mrjj that wasn't it exactly, but you put me on the right track. I'll report back in a bit.
Thanks...
-
@mrjj great suggestion there! Long story short, I had a cyclic dependency. Thanks for your help on this.
-
Super :)
Well it's my number one suspect when it says "don't know symbol"
and you check you have the header included and all seem fine.