Results 1 to 3 of 3

Thread: QXmlStreamReader error on first line?

  1. #1
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QXmlStreamReader error on first line?

    I'm not really sure how to work with QXmlStreamReader yet so I'm not sure why it's not working correctly (got the writer to work fine...) Could anyone point out my mistake(s)? I'm getting these errors :

    Current Text Invalid
    XML ERROR:1: Premature end of document.

    //QXmlStreamReader reader;

    Qt Code:
    1. void XmlHandle::readData() {
    2. std::cout << "Ready to read data\n";
    3. if(!fileName.isNull()) {
    4. QFile file(fileName);
    5. if(file.open(QFile::ReadOnly | QFile::Text)) {
    6. while(!reader.atEnd()) {
    7. reader.readNext();
    8.  
    9. std::cout<< "reading Line\n";
    10. if(reader.isStartElement()) {
    11. std::cout << "At start element\n";
    12. if(reader.name() == "volume") {
    13. QString str = reader.attributes().value("address").toString();
    14. std::cout << "Vol Attribute " << str.toStdString() << "\n";
    15. }
    16. else if(reader.name() == "text") {
    17. QString str = reader.attributes().value("author").toString();
    18. std::cout << "Text Attribute " << str.toStdString() << "\n";
    19. str = reader.text().toString();
    20. std::cout << "Text Chars " <<str.toStdString() << "\n";
    21.  
    22. }
    23. else {
    24. std::cout << "Nothing" << "\n";
    25. }
    26. }
    27. else if(reader.isEndElement())
    28. std::cout<< "End element\n";
    29. else {
    30. std::cout<< "Current Text " << reader.tokenString().toStdString() << "\n";
    31. std::cout << "XML ERROR:" << reader.lineNumber() << ": " << reader.errorString().toStdString() << "\n";
    32. }
    33.  
    34. }
    35. if(reader.error() && reader.error() != QXmlStreamReader::PrematureEndOfDocumentError)
    36. std::cout << "XML ERROR:" << reader.lineNumber() << ": " << reader.errorString().toStdString() << "\n";
    37. //std::cout << "Error is : " << reader.errorString().toStdString() << "\n";
    38. }
    39. else {
    40. std::cout << "Couldn't open " << fileName.toStdString();
    41. }
    42. }
    43. else {
    44. std::cout << "Could not fine file " << fileName.toStdString();
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 


    XML:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project version="1.0" project="Basa">
    3. <volume number="2">
    4. <chapter number="33">
    5. <page name="ahh.jpg">
    6. <bubble type="Rectangle" style="Normal" bgcolor="Qt::red">
    7. <point x="20" y="20"/>
    8. <point x="20" y="20"/>
    9. <text style="Normal">It's time you be eodiijijoj</text>
    10. </bubble>
    11. <bubble type="Rectangle" style="Normal" bgcolor="Qt::red">
    12. <point x="20" y="20"/>
    13. <point x="20" y="20"/>
    14. <text style="Normal">It's time you be eodiijijoj</text>
    15. </bubble>
    16. <bubble type="Rectangle" style="Normal" bgcolor="Qt::red">
    17. <point x="20" y="20"/>
    18. <point x="20" y="20"/>
    19. <text style="Normal">It's time you be eodiijijoj</text>
    20. </bubble>
    21. </page>
    22. </chapter>
    23. </volume>
    24. </project>
    To copy to clipboard, switch view to plain text mode 
    Last edited by warry; 13th August 2008 at 12:46.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QXmlStreamReader error on first line?

    I don't see
    Qt Code:
    1. reader.setDevice(&file);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QXmlStreamReader error on first line?

    Ah, that's the line. Thanks a lot.

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.