QtXmlPatterns - QXmlStreamWriter problem
Hi,
I've recently noticed that I'm not getting any output from QXmlStreamWriter...
As I didn't change the code I presume something happened to Qt?
I've even tried this example:
Code:
#include <QtGui>
#include <QtXmlPatterns>
int main(int argc, char* argv[])
{
QXmlStreamWriter xml(file);
xml.writeStartElement("template");
xml.writeStartElement("document");
xml.writeEndElement();
xml.writeEndDocument();
return 0;
}
It compiles ok, but the file test.xml is empty...
I'm using Kubuntu 9.04. Did anyone notice any problems with Qt4 and XML?
Thanks in advance for your help,
Regards,
Bill
Re: QtXmlPatterns - QXmlStreamWriter problem
You forgot to close the file and delete the pointer to QFile. You may either allocate QFile in the stack instead of in the heap or destroy the object:
Code:
int main(int argc, char* argv[])
{
QXmlStreamWriter xml(&file);
xml.writeStartElement("template");
xml.writeStartElement("document");
xml.writeEndElement();
xml.writeEndDocument();
file.close();
return 0;
}
Re: QtXmlPatterns - QXmlStreamWriter problem
Hi,
Well, works now :-). I overlooked file.close();. Thanks for your help.
Regards,
Bill