the*_*inX 4 c++ qt qt4 integer-overflow
我正在玩QFtp(是的......我知道)并且一切正常.
使用他们自己的示例中的代码作为指导.
http://doc.qt.io/archives/qt-4.7/network-qftp-ftpwindow-cpp.html
我遇到的唯一问题是发送(或接收)大文件(比方说3 GB)时,进度条会出现故障.
这是由于从qint64到int的强制转换:
void FtpWindow::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(readBytes);
}
Run Code Online (Sandbox Code Playgroud)
我想知道在谷歌搜索大约一个小时之后处理这个问题最好的办法是什么,并通过确保我不会超出范围来确保它"安全".
while (totalBytes > 4294967295UL)
{
totalBytes = totalBytes/4294967295UL;
readBytes = readBytes/4294967295UL;
}
Run Code Online (Sandbox Code Playgroud)
但这并不"感觉"正确..
您可以使进度条以百分比形式显示进度:
void FtpWindow::updateDataTransferProgress(qint64 readBytes,
qint64 totalBytes)
{
progressDialog->setMaximum(100);
progressDialog->setValue((qint)((readBytes * 100) / totalBytes));
}
Run Code Online (Sandbox Code Playgroud)