Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Downloading XML file
Forum Updated to NodeBB v4.3 + New Features

Downloading XML file

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 977 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdeljalil
    wrote on last edited by
    #1

    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:

    @
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QNetworkAccessManager manager = new QNetworkAccessManager ;
    QNetworkRequest request(QUrl("http://api.openweathermap.org/data/2.5/weather?q=skikda&mode=xml"));
    QNetworkReply
    reply = manager->get( request) ;
    QXmlStreamReader reader( reply );

    return a.exec();
    

    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      QNetworkAccessManager works asynchronously. That means that at line 7 in your code, the reply is still empty. You need to wait for "finished":http://qt-project.org/doc/qt-5/qnetworkaccessmanager.html#finished signal to be emitted by QNAM, and then proceed to save/ parse the reply, check for errors, etc.

      This is best done by introducing a new class, with a slot defined and connected to QNAM::finished() singal. The main routine is not a good place to do it, although it is still possible.

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved