2016-11-12 159 views
0

我想在下載文件時顯示進度條百分比。當文件下載時,我得到64%,而不是100%。如何解決這個問題?提前致謝。 enter image description hereQt進度條百分比問題

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")); 
} 

回答

0

progressPercentage計算是錯誤的。在100%,你做了80 * 80/100 = 64

將其更改爲

int progressPercentage = (totalMBReceived * 100)/totalSize; 
+0

謝謝您的回答。 – Cobra91151