How beautifully pour qint64 into int for QProgressBar

I play with QFtp (yes, I know) and everything works well.

Using code from your own example (s) as a guide.

http://doc.qt.io/archives/qt-4.7/network-qftp-ftpwindow-cpp.html

The only problem I encountered is sending (or receiving) large files (say 3 GB), the progress bar is buggy.

This is due to a cast from qint64 to int:

void FtpWindow::updateDataTransferProgress(qint64 readBytes, 
    qint64 totalBytes) 
{
    progressDialog->setMaximum(totalBytes);
    progressDialog->setValue(readBytes);
}

I wonder what would be the most wonderful way to handle this after he worked for about an hour and decided to keep it safe, making sure that I did not go out of range.

while (totalBytes > 4294967295UL)
{ 
   totalBytes = totalBytes/4294967295UL;
   readBytes = readBytes/4294967295UL;
}

But this is wrong".,

+3
source share
2 answers

:

void FtpWindow::updateDataTransferProgress(qint64 readBytes, 
    qint64 totalBytes) 
{
    progressDialog->setMaximum(100);
    progressDialog->setValue((qint)((readBytes * 100) / totalBytes));
}
+7

0-100 , .

+1

Source: https://habr.com/ru/post/1790667/


All Articles