0
ui->progressBar->setTextVisible(true);
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(readBytes);
double speed = readBytes * 1000.0/downloadTime.elapsed();
QString unit;
if (speed < 1024) {
unit = "bytes/sec";
} else if (speed < 1024*1024) {
speed /= 1024;
unit = "kB/s";
} else {
speed /= 1024*1024;
unit = "MB/s";
}
QString spd = QString::number(speed);
ui->progressBar->setFormat(spd+" "+unit);
它的工作原理是這樣的:http://i.imgur.com/RWviR8P.pngQt5:如何修改下載速度以顯示1.xx MB/s而不是1.xxxxx MB/s?
我應該如何修改這個代碼來顯示速度像1.XX MB/s的? 感謝您的幫助