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. Network download
Forum Updated to NodeBB v4.3 + New Features

Network download

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 302 Views 2 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.
  • D Offline
    D Offline
    Dan203
    wrote on last edited by
    #1

    I'm trying to port an old MFC dialog to Qt. This dialog is used to download multiple files from an internet server into my app. The way it works now is it calls a PHP file on the server which then returns a simple text file that is a pipe separated list of all the files available. It then separates those files into a vector of strings and goes into a loop which downloads each file one by one. It does this in a separate thread so as not to block the UI, but otherwise it's completely synchronous so I know exactly where I am in the loop.

    I looked at the download file example in the Qt docs but it's only designed to download one file and uses a slot/signal to process each file so it's asynchronous. So I'm not sure how exactly to duplicate my functionality. Do I need multiple QNetworkManager objects pointing to different slots? (i.e. one to process the list and one to process the actual file downloads) Or is there some better way to do this that I'm not seeing?

    JKSHJ 1 Reply Last reply
    0
    • D Dan203

      I'm trying to port an old MFC dialog to Qt. This dialog is used to download multiple files from an internet server into my app. The way it works now is it calls a PHP file on the server which then returns a simple text file that is a pipe separated list of all the files available. It then separates those files into a vector of strings and goes into a loop which downloads each file one by one. It does this in a separate thread so as not to block the UI, but otherwise it's completely synchronous so I know exactly where I am in the loop.

      I looked at the download file example in the Qt docs but it's only designed to download one file and uses a slot/signal to process each file so it's asynchronous. So I'm not sure how exactly to duplicate my functionality. Do I need multiple QNetworkManager objects pointing to different slots? (i.e. one to process the list and one to process the actual file downloads) Or is there some better way to do this that I'm not seeing?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @Dan203 said in Network download:

      Do I need multiple QNetworkManager objects pointing to different slots? (i.e. one to process the list and one to process the actual file downloads)

      Nope, you use a single QNetworkAccessManager and call get() on it multiple times. Each time you call get(), it returns a unique QNetworkReply object.

      The downloads occur asynchronously, as you have found. Each QNetworkReply will emit its own finished() signal when it has finished downloading. (The QNetworkAccessManager also emits a finished() that contains the pointer to the relevant QNetworkReply)

      Connect the finished() signal to a slot. In the slot, you can call QNetworkReply::url() to see what was downloaded. Based on the URL, you can either process the file contents as a list, or save the file contents to disk.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      D 1 Reply Last reply
      3
      • JKSHJ JKSH

        @Dan203 said in Network download:

        Do I need multiple QNetworkManager objects pointing to different slots? (i.e. one to process the list and one to process the actual file downloads)

        Nope, you use a single QNetworkAccessManager and call get() on it multiple times. Each time you call get(), it returns a unique QNetworkReply object.

        The downloads occur asynchronously, as you have found. Each QNetworkReply will emit its own finished() signal when it has finished downloading. (The QNetworkAccessManager also emits a finished() that contains the pointer to the relevant QNetworkReply)

        Connect the finished() signal to a slot. In the slot, you can call QNetworkReply::url() to see what was downloaded. Based on the URL, you can either process the file contents as a list, or save the file contents to disk.

        D Offline
        D Offline
        Dan203
        wrote on last edited by
        #3

        @JKSH thanks, that is very helpful

        1 Reply Last reply
        1

        • Login

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