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. QProgressBar with QNetworkReply
Qt 6.11 is out! See what's new in the release blog

QProgressBar with QNetworkReply

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 6.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.
  • K Offline
    K Offline
    Ketan Shah
    wrote on last edited by
    #1

    Hi,
    I am making an application which downloads zip files from internet and extracts it in a particular folder.
    The code below shows a progressbar for downloading the files from internet.
    what I want to do is to show a progressbar for both downloading and extracting, at present the progressbar for downloading is shown properly but unable to show it for extracting.
    I want to set around 80% for downloading and the remaining 20% for extracting, how can I do this, can any one help me find out a solution for this.

    @update::update(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::update)
    {

    bar = new QProgressBar (this);
    bar->setStyle(new QPlastiqueStyle);
    QNetworkRequest request(url);
    currentDownload = manager.get(request);
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
    SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()),
    SLOT(downloadFinished()));

    }

    void update::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
    {
    bar->setMaximum(bytesTotal);
    bar->setValue(bytesReceived);
    bar->show();
    }@

    Thanks in advance.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Why not just set a higher maximum? This way the progress bars end at 80% after the download.
      @
      void update::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
      {
      bar->setMaximum(bytesTotal + (bytesTotal * 0.25));
      bar->setValue(bytesReceived);
      bar->show();
      }
      @

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Ketan Shah
        wrote on last edited by
        #3

        Thanks it worked, downloading gets completed on 80%.
        Now how can I allot the remaining 20% to unzip process, if you can then please help.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          Well, just increase the value until you reach the maximum.
          @
          class update
          {
          ...

          private:
          int _extractionStep;
          }

          void update::startExtraction()
          {
          // intermediateSteps depends on how your extraction works. if your
          // extractionProgress() slot is for example called every percent
          // extracted intermediateSteps will be 100.

          _extractionStep = (bar->maximum() - bar->value()) / intermediateSteps;
          

          }

          void update::extractionProgress()
          {
          bar->setValue(bar->()value + _extractionStep);
          }
          @

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Ketan Shah
            wrote on last edited by
            #5

            Thanks for the help your code is working as expected, but for extracting I am using QProcess::execute, but this makes the GUI and the progressbar inactive.
            The GUI and progressbar becomes active after QProcess::execute have finished its work, also I cannot use QProcess::start as it goes in the background and returns the exit code immediately.
            The reason why I am using QProcess::execute is that it returns the exit code after completing the work.

            Is there any way that can make QProcess::execute and progressbar work simulataneuosly ?
            Can I use QThread ? if yes, how ?

            Thanks for the help.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Use QProcess::start() and connect to the "QProcess::finished()":http://developer.qt.nokia.com/doc/qt-4.8/qprocess.html#finished signal, which is emitted as soon as the process has finished and passes the exit code to the slot.

              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