Results 1 to 3 of 3

Thread: Downloading XML file

  1. #1
    Join Date
    Mar 2014
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Downloading XML file

    Hello,
    i want to get a XML file from online source,
    example:
    http://api.openweathermap.org/data/2...kikda&mode=xml
    how can i download it and store the data in QTemporaryFile or pass it directly to QXmlStreamReader
    i tried a lot but i dont know what is the problem exactly
    example:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4. QNetworkAccessManager *manager = new QNetworkAccessManager;
    5. QNetworkRequest request(QUrl("http://api.openweathermap.org/data/2.5/weather?q=skikda&mode=xml"));
    6. QNetworkReply* reply = manager->get( request) ;
    7. QXmlStreamReader reader( reply );
    8.  
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Downloading XML file

    QNetworkAccessManager works asynchronous, the get() call returns immediately and the actual transfer happens over time.

    QNetworkReply is a QIODevice so it will signal incoming data via its readyRead() signal.
    You can also wait for it to finish() and then read all data in one go.

    QXmlStreamReader supports both partial data and full documents.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Downloading XML file

    But none of this will happen if the app's event loop isn't running. So putting that code into main() before the QCoreApplication::exec() call will have no effect at all since there is no event loop yet to handle signals.

Similar Threads

  1. Downloading file problem
    By Kaluss in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2014, 10:50
  2. Proper file downloading?
    By matt4682 in forum Newbie
    Replies: 4
    Last Post: 2nd May 2014, 11:45
  3. Replies: 1
    Last Post: 27th July 2013, 23:57
  4. downloading the file problems
    By migel in forum Newbie
    Replies: 0
    Last Post: 7th June 2011, 18:30
  5. File size of a remote file without downloading it
    By dirkdepauw in forum Qt Programming
    Replies: 5
    Last Post: 4th November 2010, 10:48

Tags for this Thread

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.