Results 1 to 3 of 3

Thread: XML read problem

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default XML read problem

    I encountered a strange thing while trying to read xml. I used code that almost anyone used to parse XML. The thing is - i cannot get mine program to read the full XML at once. Instead it reads the page dividing it into parts, and each time it reads the html - it divides it into different parts. Is there anyway to make the program read the xml after it got all the data?

    two of many functions I used:
    void List::readData(const QHttpResponseHeader &resp)
    Qt Code:
    1. void List::readData(const QHttpResponseHeader &resp)
    2. {
    3. if (resp.statusCode() != 200)
    4. http.abort();
    5. else
    6. {
    7. xml.addData(http.readAll());
    8. parseXml();
    9. }
    10. }
    11.  
    12. void List::finished(int id, bool error)
    13. {
    14. if (error)
    15. {
    16. QMessageBox::warning(this, "Error", http.errorString());
    17.  
    18. }
    19. else if (id == connectionId)
    20. {
    21.  
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: XML read problem

    QHttp class reference says:

    "This class provides a direct interface to HTTP that allows you to download and upload data with the HTTP protocol. However, for new applications, it is recommended to use QNetworkAccessManager and QNetworkReply, as those classes possess a simpler, yet more powerful API and a more modern protocol implementation."

    Maybe You should Use QNetworkAccessManager and QNetworkReply? I use It to download XML file, and it works well (only in one case I have problems with it).

    Qt Code:
    1. void MainWindow::getXML()
    2. {
    3. QNetworkRequest request(QUrl("http://something.com"));
    4. NetRepl = NetAccMan.get(request);
    5. connect(NetRepl, SIGNAL(readyRead()), this, SLOT(parseXML()));
    6. }
    7.  
    8. void MainWindow::parseXML()
    9. {
    10. //parse Your XML
    11. }
    12.  
    13. best regards
    14. Tomasz
    To copy to clipboard, switch view to plain text mode 

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

    Archa4 (7th February 2011)

  4. #3
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: XML read problem

    Thanks, I'll look into QNetAccMan...
    I solved mine problem moving the parseXml into finished function...

Similar Threads

  1. Replies: 1
    Last Post: 18th October 2010, 16:07
  2. Replies: 4
    Last Post: 17th September 2010, 20:18
  3. Problem in printing the data return /read from QTcpsocket
    By skumar434 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 19:36
  4. External Lib read from QBuffer on Calback problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2008, 19:43
  5. problem with read blob from postgres db
    By zlatko in forum Qt Programming
    Replies: 4
    Last Post: 5th November 2006, 08:30

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.