2016-11-12 231 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