Results 1 to 3 of 3

Thread: QtXmlPatterns - QXmlStreamWriter problem

  1. #1
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:
    Qt Code:
    1. #include <QtGui>
    2. #include <QtXmlPatterns>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QFile *file = new QFile("test.xml");
    9. file->open(QFile::WriteOnly | QFile::Text);
    10. QXmlStreamWriter xml(file);
    11. xml.writeStartElement("template");
    12. xml.writeStartElement("document");
    13. xml.writeEndElement();
    14. xml.writeEndDocument();
    15.  
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QFile file("test.xml");
    6. file.open(QFile::WriteOnly | QFile::Text);
    7. QXmlStreamWriter xml(&file);
    8. xml.writeStartElement("template");
    9. xml.writeStartElement("document");
    10. xml.writeEndElement();
    11. xml.writeEndDocument();
    12. file.close();
    13.  
    14. return 0;
    15. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to vfernandez for this useful post:

    Bill (26th August 2009)

  4. #3
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtXmlPatterns - QXmlStreamWriter problem

    Hi,
    Well, works now :-). I overlooked file.close();. Thanks for your help.

    Regards,
    Bill

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.