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. How to make a progress bar for downloads?
Forum Updated to NodeBB v4.3 + New Features

How to make a progress bar for downloads?

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 10.7k 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.HilkJ J.Hilk

    @Armin
    hi,

    You don't give us much information here :-)

    But I'll just asume, you use QT's Networkaccess Manager to do your downloading:
    So I'll post a section from my own project.

    First: You get the SIGNAL of your Networkreply:

     QNetworkReply *reply = NetworkManager->get(downloadRequest);
    
        connect(reply, &QNetworkReply::downloadProgress,this, &NetworkAccess::downloadProgress);
    
    

    Second: In your downloadProgess slot you set the values of your Progressbar:

    void NetworkAccess::downloadProgress(qint64 ist, qint64 max)
    {
        pBar->setRange(0,max);
        pBar->setValue(ist);
        if(max < 0) hideProgress();
    }
    

    simple and straight forward :-)

    A Offline
    A Offline
    Armin
    wrote on last edited by
    #7

    @J.Hilk what are ist and max arguments ? where they come from?
    thnaks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Armin
      wrote on last edited by
      #8
      ```
      

      connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*)));
      manager->get(QNetworkRequest(QUrl(downloadlink)));

      
      

      void MainWindow::replyFinished(QNetworkReply *reply)
      {
      connect(reply, &QNetworkReply::downloadProgress,this, &MainWindow:: progressbar);
      .
      .
      .
      .

      
      Where i did wrong?
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #9

        Hi,

        Aren't you connecting the downloadProgress signal once the reply is finished ? By finished it means that the query has completed so you are trying to get the download information after the download already happened.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply
        5
        • SGaistS SGaist

          Hi,

          Aren't you connecting the downloadProgress signal once the reply is finished ? By finished it means that the query has completed so you are trying to get the download information after the download already happened.

          A Offline
          A Offline
          Armin
          wrote on last edited by
          #10

          @SGaist Thanks

              QNetworkAccessManager *manager = new QNetworkAccessManager(this);
              QNetworkReply *reply;
              connect(manager , SIGNAL(downloadProgress(qint64,qint64)) , this , SLOT(progressbar(qint64,qint64)));
              connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*)));
              manager->get(QNetworkRequest(QUrl(downloadlink)));
          

          What i do?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #11

            Meaning ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            1
            • SGaistS SGaist

              Meaning ?

              A Offline
              A Offline
              Armin
              wrote on last edited by
              #12

              @SGaist Where i did wrong in that code?

              J.HilkJ 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #13

                Since it's outside any context the only thing that can be said is that reply is not used and that you are likely going to have lots of memory eaten if you create a new QNetworkAccessManager per query and not deleting it afterward.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • A Armin

                  @SGaist Where i did wrong in that code?

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #14

                  @Armin
                  hi,

                  in your sample, not the QNetworkAccessManager has the downloadProgress Signal, but the QNetworkReply

                  ->

                  QNetworkAccessManager *manager = new QNetworkAccessManager(this);
                      QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(downloadlink)));
                      connect(reply, SIGNAL(downloadProgress(qint64,qint64)) , this , SLOT(progressbar(qint64,qint64)));
                      connect(manager , SIGNAL(finished(QNetworkReply*)) , this , SLOT(replyFinished(QNetworkReply*)));
                      
                  ``

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  4
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    To add to @J-Hilk which got the wrong connection I missed, you should provide more context on how you are using that code in your application.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Armin
                      wrote on last edited by
                      #16

                      Thanks for all
                      My problem solved.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        What was the problem ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2

                        • Login

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