Qt5:如何修改下载速度以显示 1.xx MB/s 而不是 1.xxxxx MB/s
Qt5: how to modify download speed to show 1.xx MB/s instead of 1.xxxxx MB/s?
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);
它的工作原理是这样的:https://i.stack.imgur.com/86bzs.png
我应该如何修改此代码以显示速度,例如 1.XX MB/s ?感谢您的帮助
你应该使用 QString::number 的第三个参数:
QString::number(1.6183456, 'f', 2)
// -> "1.62"
相关文章:
- 为什么我只能在C++中使用可变长度数组分配小于 10 mb 的内存?
- C++ 将打印格式从整数 2255 更改为 $xx.xx
- 为什么这个.c文件只有一行"../xx/xx.c"?
- 当我读取一个大小为 17 mb 的 100 万个 url 文件时,我的程序占用大小为 163 MB
- 问题 (std::bad_alloc) 通过 QThread 中的 QSqlQuery 将大图像(约 36 MB)保存到
- 无法在打开的 cv 3.xx 中画线
- 在静态成员函数中无效使用成员“xx::x”
- 平息海湾合作委员会的"only available with -std=c++XX or -std=gnu++XX"警告
- ITK:在执行 HelloWorld 示例时找不到 ITKCommon-x.xx.dll
- Windows C++ UWP:等待 XX 毫秒,直到事件发生
- 无法在 Mac OS X 上分配内存错误 - java(xx,xx) malloc: *** mmap(size=XX)
- Qt5:如何修改下载速度以显示 1.xx MB/s 而不是 1.xxxxx MB/s
- Libtorrent 速度上限为 1 MB/s
- QSqlQuery使用数百MB的内存
- 如何创建代码隔离大小应该是16 mb(字节码)大小的c ++程序
- LoadLibrary(xx.dll) with error 126
- 基于内核版本 X.XX 构建的 C++ Linux 应用是否会在早期版本上运行
- 是否有可以在控制台中设置颜色的 WinAPI 调用,如'color xx'命令?
- 查找科学记数法 (E+XX)
- 字符串打印机问题:参数 X 没有从“char (*)[xx]”到“char**”的已知转换