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. [SOLVED]Download file without main event loop
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Download file without main event loop

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k 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.
  • J Offline
    J Offline
    Jake007
    wrote on last edited by JKSH
    #1

    Hi!

    I'd like to download a file, so that when download is started, it does not does not execute next command until file is downloaded.

    An example of what I want:

    QNetworkAccessManager nam;
    QNetworkReply *r = nam.get(QNetworkRequest(QUrl("http://URL")));
    QByteArray data = r.readAll(); // Everything already downloaded, even if file is several GB in size
    

    I want my app to download a file, save it, and then exit. Nothing more. It'll be started with QProcess, so there will be no GUI and no Qt event loop.

    Regards,
    Jake


    Code is poetry

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by JKSH
      #2

      It's actually a bad idea. get() is already asynchronous so you don't need to put it in an explicit QProcess.
      But if you have to, the very ugly solution would be something like this:

      QNetworkAccessManager nam;
      QNetworkReply *r = nam.get(QNetworkRequest(QUrl("http://URL")));
      while(!r->isFinished()) qApp->processEvents();
      QByteArray data = r.readAll(); // Everything already downloaded, even if files is several GB in size
      
      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on last edited by
        #3

        My plan was, that I'd retrieve current version of the program from the updater, because it already has all functions written for version checking, updating...
        I'd start it with parameter, -v for example, and in this case program would only retrieve and output latest version. Main program would correctly correspond to received message.

        But based on your solution ( ugly as you said), I'll probably just copy the code, or create a shared library ( just thought of this solution).

        Thanks!

        Regards,
        Jake


        Code is poetry

        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