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. QT Network Download Example does not run in parallel!

QT Network Download Example does not run in parallel!

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.9k Views
  • 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.
  • L Offline
    L Offline
    Limo
    wrote on last edited by
    #1

    void DownloadManager::progress(qint64 done, qint64 total)
    {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    QUrl url = reply->url();
    QFileInfo info(QString(url.toEncoded().constData()));
    qDebug()<<info.fileName()<<done<<total;
    }

    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(progress(qint64,qint64)));

    i write like this. It seems like to output filename alternate.
    But it didn't start next one until the current finish.

    jsulmJ 1 Reply Last reply
    0
    • L Limo

      void DownloadManager::progress(qint64 done, qint64 total)
      {
      QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
      QUrl url = reply->url();
      QFileInfo info(QString(url.toEncoded().constData()));
      qDebug()<<info.fileName()<<done<<total;
      }

      connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(progress(qint64,qint64)));

      i write like this. It seems like to output filename alternate.
      But it didn't start next one until the current finish.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Limo You should show how you start those parallel downloads.

      L 1 Reply Last reply
      0
      • L Offline
        L Offline
        Limo
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @Limo You should show how you start those parallel downloads.

          L Offline
          L Offline
          Limo
          wrote on last edited by
          #4

          @jsulm
          in the example http://doc.qt.io/qt-5/qtnetwork-download-main-cpp.html

          void DownloadManager::execute()
          {
             QStringList args = QCoreApplication::instance()->arguments();
             args.takeFirst();           // skip the first argument, which is the program's name
             if (args.isEmpty()) {
                 printf("Qt Download example - downloads all URLs in parallel\n"
                        "Usage: download url1 [url2... urlN]\n"
                        "\n"
                        "Downloads the URLs passed in the command-line to the local directory\n"
                        "If the target file already exists, a .0, .1, .2, etc. is appended to\n"
                        "differentiate.\n");
                 QCoreApplication::instance()->quit();
                 return;
             }
             foreach (QString arg, args) {
                 QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
                 doDownload(url);
             }
          }
          

          in this function,just instead the foreach with :

          doDownload(url1);
          doDownload(url2);
          
          jsulmJ 2 Replies Last reply
          0
          • L Limo

            @jsulm
            in the example http://doc.qt.io/qt-5/qtnetwork-download-main-cpp.html

            void DownloadManager::execute()
            {
               QStringList args = QCoreApplication::instance()->arguments();
               args.takeFirst();           // skip the first argument, which is the program's name
               if (args.isEmpty()) {
                   printf("Qt Download example - downloads all URLs in parallel\n"
                          "Usage: download url1 [url2... urlN]\n"
                          "\n"
                          "Downloads the URLs passed in the command-line to the local directory\n"
                          "If the target file already exists, a .0, .1, .2, etc. is appended to\n"
                          "differentiate.\n");
                   QCoreApplication::instance()->quit();
                   return;
               }
               foreach (QString arg, args) {
                   QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
                   doDownload(url);
               }
            }
            

            in this function,just instead the foreach with :

            doDownload(url1);
            doDownload(url2);
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • L Limo

              @jsulm
              in the example http://doc.qt.io/qt-5/qtnetwork-download-main-cpp.html

              void DownloadManager::execute()
              {
                 QStringList args = QCoreApplication::instance()->arguments();
                 args.takeFirst();           // skip the first argument, which is the program's name
                 if (args.isEmpty()) {
                     printf("Qt Download example - downloads all URLs in parallel\n"
                            "Usage: download url1 [url2... urlN]\n"
                            "\n"
                            "Downloads the URLs passed in the command-line to the local directory\n"
                            "If the target file already exists, a .0, .1, .2, etc. is appended to\n"
                            "differentiate.\n");
                     QCoreApplication::instance()->quit();
                     return;
                 }
                 foreach (QString arg, args) {
                     QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
                     doDownload(url);
                 }
              }
              

              in this function,just instead the foreach with :

              doDownload(url1);
              doDownload(url2);
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Limo How big are the files?
              How do you know it did not start second download while first one is running?

              L 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Limo How big are the files?
                How do you know it did not start second download while first one is running?

                L Offline
                L Offline
                Limo
                wrote on last edited by
                #7

                @jsulm
                they are 50~60MB.
                i wrote this function:

                void DownloadManager::progress(qint64 done, qint64 total)
                {
                QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
                QUrl url = reply->url();
                QFileInfo info(QString(url.toEncoded().constData()));
                qDebug()<<info.fileName()<<done<<total;
                }
                

                and

                connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
                

                if the second download has ran ,it may output its info.But i didn't saw the second download's info when the first is running.

                jsulmJ 1 Reply Last reply
                0
                • L Limo

                  @jsulm
                  they are 50~60MB.
                  i wrote this function:

                  void DownloadManager::progress(qint64 done, qint64 total)
                  {
                  QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
                  QUrl url = reply->url();
                  QFileInfo info(QString(url.toEncoded().constData()));
                  qDebug()<<info.fileName()<<done<<total;
                  }
                  

                  and

                  connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
                  

                  if the second download has ran ,it may output its info.But i didn't saw the second download's info when the first is running.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Limo Where do you call

                  connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
                  

                  Do you call it for all replies?

                  L 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Limo Where do you call

                    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
                    

                    Do you call it for all replies?

                    L Offline
                    L Offline
                    Limo
                    wrote on last edited by
                    #9

                    @jsulm

                    void DownloadManager::doDownload(const QUrl &url)
                    {
                        QNetworkRequest request(url);
                        QNetworkReply *reply = manager.get(request);
                    
                    #ifndef QT_NO_SSL
                        connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(sslErrors(QList<QSslError>)));
                    #endif
                    
                        connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
                        currentDownloads.append(reply);
                    }
                    
                    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