Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, August 2007
QXmlStreamWriter problem


Message 1 in thread

Hi

Trying to use the QXmlStreamWriter but something is wrong

the code looks like:

QString fileName = QFileDialog::getSaveFileName(0, "Save File", "",
"XML Files ( *.xml)");

file = new QFile();
file->setFileName(fileName);

xmlWriter = new QXmlStreamWriter();
xmlWriter->setDevice(file);
xmlWriter->writeStartDocument();
xmlWriter->writeDTD("<!DOCTYPE xbel>");

xmlWriter->writeStartElement("ThisIsStartElement");
xmlWriter->writeAttribute("version", "1.0");
xmlWriter->writeEndDocument();


now the file is created, but there is nothing in it, so I am missing
something and I found a bookmark example in the QT doc but cant find
anything that is made different there, anybody?

thanks
// anders

--
 [ signature omitted ] 

Message 2 in thread

try closing the file, or use a file on the stack.
here is a working example of QXmlStreamWriter:
http://doc.trolltech.com/4.3/xml-streambookmarks.html

Cheers,
Peter

> now the file is created, but there is nothing in it, so I am missing
> something and I found a bookmark example in the QT doc but cant find
> anything that is made different there, anybody?
> 
> thanks
> // anders

--
 [ signature omitted ] 

Message 3 in thread

You need to open the file before using it.

file = new QFile(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text))
    QMessageBox::warning(...)
xmlWriter = new QXmlStreamWriter(&file);

This should do the trick.

(I also used constructor arguments instead of methods, but that doesn't change 
any behaviour.)

Sincerely,

Bo Thorsen.

On mandag den 20. August 2007, Anders Sandholm wrote:
> Hi
>
> Trying to use the QXmlStreamWriter but something is wrong
>
> the code looks like:
>
> QString fileName = QFileDialog::getSaveFileName(0, "Save File", "",
> "XML Files ( *.xml)");
>
> file = new QFile();
> file->setFileName(fileName);
>
> xmlWriter = new QXmlStreamWriter();
> xmlWriter->setDevice(file);
> xmlWriter->writeStartDocument();
> xmlWriter->writeDTD("<!DOCTYPE xbel>");
>
> xmlWriter->writeStartElement("ThisIsStartElement");
> xmlWriter->writeAttribute("version", "1.0");
> xmlWriter->writeEndDocument();
>
>
> now the file is created, but there is nothing in it, so I am missing
> something and I found a bookmark example in the QT doc but cant find
> anything that is made different there, anybody?

-- 
 [ signature omitted ] 

Message 4 in thread

Thanks for the code and it helpt, because before I tested for write only:

if (!file->open(QFile::WriteOnly | QFile::Text)) {
         QMessageBox::warning(0, "Write Only",
                              "The file is in write only mode");
     }

and it didnt give a warning, so I thought that it was ok, but then I
took your code and ran

if (!file->open(QFile::ReadOnly | QFile::Text)){
		QMessageBox::warning(0, "Read only",
                              "The file is in read only mode");
	}

and this where true, so I think the problem is that the file is in
read only mode. Can I change this, or create the file in some other
way, I create the file so why is it in read only mode?


regards
Anders


On 8/21/07, Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx> wrote:
> You need to open the file before using it.
>
> file = new QFile(fileName);
> if (!file.open(QFile::ReadOnly | QFile::Text))
>     QMessageBox::warning(...)
> xmlWriter = new QXmlStreamWriter(&file);
>
> This should do the trick.
>
> (I also used constructor arguments instead of methods, but that doesn't change
> any behaviour.)
>
> Sincerely,
>
> Bo Thorsen.
>
> On mandag den 20. August 2007, Anders Sandholm wrote:
> > Hi
> >
> > Trying to use the QXmlStreamWriter but something is wrong
> >
> > the code looks like:
> >
> > QString fileName = QFileDialog::getSaveFileName(0, "Save File", "",
> > "XML Files ( *.xml)");
> >
> > file = new QFile();
> > file->setFileName(fileName);
> >
> > xmlWriter = new QXmlStreamWriter();
> > xmlWriter->setDevice(file);
> > xmlWriter->writeStartDocument();
> > xmlWriter->writeDTD("<!DOCTYPE xbel>");
> >
> > xmlWriter->writeStartElement("ThisIsStartElement");
> > xmlWriter->writeAttribute("version", "1.0");
> > xmlWriter->writeEndDocument();
> >
> >
> > now the file is created, but there is nothing in it, so I am missing
> > something and I found a bookmark example in the QT doc but cant find
> > anything that is made different there, anybody?
>
> --
>
> Thorsen Consulting ApS - Qt consulting services
> http://www.thorsen-consulting.dk
>
> --
> 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/
>
>

--
 [ signature omitted ]