Solved How to add xml?
-
I am trying to build a simple xml reader using qt's stream reader. But I am running into trouble when I try to use xml
I get
C:\CPP\XmlTest\XmlTest\xmlreader.cpp:17: error: C2065: 'xml': undeclared identifier
below is the .cpp
#include "xmlreader.h" #include <qxmlstream.h> #include <qfile.h> XmlReader::XmlReader( const QString filename ) { this->filename_ = filename; } void XmlReader::Read() { QFile xmlfile(this->filename_); xmlfile.open( QIODevice::ReadOnly ); xml.setDevice( &xmlfile ); // ERROR HERE }
I added this to the application's .pro
QT += xml
What else do I need to do to use xml. Is there another library I need to include?
-
@zicx What is xml?
void XmlReader::Read() { QFile xmlfile(this->filename_); xmlfile.open( QIODevice::ReadOnly ); xml.setDevice( &xmlfile ); // What is xml?
So, where and how did you declare it?
-
Oh, I assumed that this is related to the +xml. some sort of way to include a special library. The example I looked at didn't declare it but it seems to be an instance of QXmlStreamReader.
Thanks for the hint -
you can also use Qtextstream to read
-
As a side note, QXmlStreamReader is part of the core module, no need to include
QT += xml
in the pro file