|
|
Hi everybody,
I have been trying to QXmlStreamWriter to create a simple XML file.
However, my file is always empty. I'm sure I'm missing something
obvious, but I have been banging my head on this for too long now.
Here is a piece of sample code that generates an empty file.
#include <QCoreApplication>
#include <QTimer>
#include <QFile>
#include <QXmlStreamWriter>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QXmlStreamWriter *file = new QXmlStreamWriter;
QFile *fileHandle = new QFile("dummy.xml");
if (!fileHandle->open(QIODevice::WriteOnly | QIODevice::Text))
return 1;
qDebug() << "File Open";
file->setDevice(fileHandle);
file->writeStartDocument();
file->writeDTD("<!DOCTYPE mytest>");
file->writeStartElement("FH");
file->writeAttribute("date","20081201");
file->writeStartElement("TEST");
file->writeCharacters("This is some test data");
file->writeEndElement();
file->writeEndElement();
file->writeEndDocument();
/** Disable this if you want to execute the event loop **/
QTimer::singleShot(0, &app, SLOT(quit()));
/***** Run the application *****/
return app.exec();
/*******************************/
}//
Any help would be appreciated.
Thanks
Marius
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|