PDA

View Full Version : QtXmlPatterns - QXmlStreamWriter problem



Bill
25th August 2009, 17:40
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:


#include <QtGui>
#include <QtXmlPatterns>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QFile *file = new QFile("test.xml");
file->open(QFile::WriteOnly | QFile::Text);
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

vfernandez
25th August 2009, 21:37
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:


int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QFile file("test.xml");
file.open(QFile::WriteOnly | QFile::Text);
QXmlStreamWriter xml(&file);
xml.writeStartElement("template");
xml.writeStartElement("document");
xml.writeEndElement();
xml.writeEndDocument();
file.close();

return 0;
}

Bill
26th August 2009, 10:18
Hi,
Well, works now :-). I overlooked file.close();. Thanks for your help.

Regards,
Bill