PDA

View Full Version : QDomDocument won't build/compile



RolandHughes
30th April 2012, 02:08
All,

I'm running QtCreator 2.2.1 on ubuntu 32-bit. Says I'm using 4.7.3 of Qt. So far so good. I needed to so some simple XML. Stole this example from this board which others claims works just fine.



#include <QtXml/QDomDocument>
#include <QtXml/QXmlSimpleReader>
#include <QDebug>

int main(){
QString xmlString("<original> </original>");
QDomDocument doc;
doc.setContent(xmlString);
QDomElement docElem = doc.documentElement();
qDebug() << "Without QXmlSimpleReader \t- element contains" <<docElem.text() << "\tlength="<< docElem.text().length();
doc.clear();
QXmlInputSource source;
source.setData(xmlString);
QXmlSimpleReader reader;
doc.setContent(&source, &reader);
docElem = doc.documentElement();
qDebug() << "With QXmlSimpleReader \t- element contains" <<docElem.text() << "\tlength="<< docElem.text().length();
}



When I try to compile I get this error along with a rash of others.

(.text.startup+0x38):-1: error: undefined reference to `QDomDocument::QDomDocument()'

The header files are all there. What is missing from this installation? It's probably something simple, it's late and I'm tired.

Thanks,
Roland

Added after 14 minutes:

Never mind

I forgot to add +=xml in the pro file

stupid things happen when you get tired.

d_stranz
30th April 2012, 23:32
You should also learn to distinguish between compile and link errors. What you have posted here looks like a link error to me, and has nothing to do with whether the header files are there or not (which they are). The error you posted is the linker telling you it can't find something it needs in the object and library files you've told it to link in. Adding +xml in pro file is specifying a link library, as you discovered.

Programming tired is like driving tired. It's better to pull over and get some rest, otherwise you may fall asleep at the wheel and run into something. :)