QProgressBar with QNetworkReply



  • 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.



  • 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();
    }
    @



  • 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.



  • 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);
    }
    @



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.