如何巧妙地“投射” QProgressBar 的 qint64 到 int
我正在使用 QFtp(是的..我知道)并且一切正常。
使用他们自己的示例中的代码作为指导。
http://doc.qt.io/archives/qt -4.7/network-qftp-ftpwindow-cpp.html
我遇到的唯一问题是发送(或接收)大文件(假设为 3 GB)时进度条出现故障。
这是由于从 qint64 到 int in 的强制转换:
void FtpWindow::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(readBytes);
}
我想知道在谷歌搜索大约一个小时后处理这个问题的最好方法是什么,并决定通过确保不超出范围来保持它的“安全” 。
while (totalBytes > 4294967295UL)
{
totalBytes = totalBytes/4294967295UL;
readBytes = readBytes/4294967295UL;
}
但这“感觉”不对。 。
I'm playing around with QFtp (yes .. I know) and all works well.
Using code from their own example(s) as a guideline.
http://doc.qt.io/archives/qt-4.7/network-qftp-ftpwindow-cpp.html
The only problem I'm having is when sending (or receiving) big files (let's say 3 GB) the progress bar glitches out.
This is due to the cast from qint64 to int in:
void FtpWindow::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(readBytes);
}
I'm wondering what would be the nicest way to handle this after googling for about an hour and settling on keeping it 'safe' by making sure I don't go out of range.
while (totalBytes > 4294967295UL)
{
totalBytes = totalBytes/4294967295UL;
readBytes = readBytes/4294967295UL;
}
But that doesn't "feel" right . .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使进度条以百分比形式显示进度:
You can make the progress bar present the progress as a percentage:
将进度条设置为 0-100 范围,并显示读取的字节百分比,而不是尝试设置绝对值。
Set your progress bar to a range of 0-100, and display the percentage of bytes read instead of trying to set the absolute value.