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.
- ui(new Ui::update)
- {
- 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.
5 replies
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() [developer.qt.nokia.com] signal, which is emitted as soon as the process has finished and passes the exit code to the slot.
You must log in to post a reply. Not a member yet? Register here!

