0

I want to display progressbar percentage when downloading a file. When file is downloaded i get 64%, not 100%. How to fix this issue? Thanks in advance.enter image description here

void Updates::UpdateProgress(qint64 bytesRead, qint64 totalBytes) 
{
    int totalSize = totalBytes / 1024 / 1024;
    int totalMBReceived = bytesRead / 1024 / 1024;

    ui->progressBar->setMaximum(totalSize);
    ui->progressBar->setValue(totalMBReceived);

    int progressPercentage = (totalSize * totalMBReceived) / 100;
    qDebug() << progressPercentage;

    ui->label->setText(QString::number(progressPercentage).append("%"));
    ui->label_4->setText(QString::number(totalSize).append(" MB") + " / " + QString::number(totalMBReceived).append(" MB"));
}
Julian Declercq
  • 1,536
  • 3
  • 17
  • 32
Cobra91151
  • 610
  • 4
  • 14

1 Answers1

0

Your progressPercentage calculation is wrong. At 100%, you did 80*80/100 = 64.

Change it to

int progressPercentage = (totalMBReceived * 100) / totalSize;
gengisdave
  • 1,969
  • 5
  • 21
  • 22