5

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 . .

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
the JinX
  • 1,950
  • 1
  • 18
  • 23

2 Answers2

7

You can make the progress bar present the progress as a percentage:

void FtpWindow::updateDataTransferProgress(qint64 readBytes, 
    qint64 totalBytes) 
{
    progressDialog->setMaximum(100);
    progressDialog->setValue((qint)((readBytes * 100) / totalBytes));
}
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 4
    Any other number than 100 would also work, of course. But if your progrssbar is e.g. 700 pixels wide, using a percentage means it will only update 7 pixels at a time. Personally, I'd pick 4096. – MSalters Feb 08 '11 at 12:36
  • Yeah maybe - percentage is a commonly used method in which to present progress though, and it really doesn't make a lot of difference – trojanfoe Feb 08 '11 at 12:38
  • 2
    Just had a devide by 0 error, when uploading a 0 byte file, so I had to add: if (totalBytes != 0) – the JinX Feb 10 '11 at 09:42
  • @the_jinx: good catch - this isn't production quality code - it just gives you the idea. – trojanfoe Feb 10 '11 at 09:45
1

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.

badgerr
  • 7,802
  • 2
  • 28
  • 43