Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress during a file saving

I have a large image that I have to save with image.save(fichier). How could I possibly display a progressbar of the saving state?

This may be a trivial question but I really don't how to do this as it's a one-line command...

like image 504
Leo Avatar asked May 30 '26 03:05

Leo


2 Answers

You probably can't using the built in image save. You could estimate the save time (know size of image, guess mb/s), and put up a progress bar and just use a timer to update it.

Or you can have a progress bar that just runs quickly to the end and restarts to show some activity but not the actual progress.

edit: if you really must have a progress you could 'save' the image data in memory and then write the memory to disk a block at a time updating the progress.

 QImage image;
 QByteArray bytes;
 QBuffer buffer(&bytes);
 buffer.open(QIODevice::WriteOnly);
 image.save(&buffer, "PNG"); // writes image into buffer in PNG format

Then write the buffer to disk

like image 120
Martin Beckett Avatar answered Jun 01 '26 17:06

Martin Beckett


You can run QImage::save() in another thread, while the main thread shows the progressbar, updating its progress value every second with expected_size/current_size. You can get current size with QFile::size()

like image 31
Alessandro Pezzato Avatar answered Jun 01 '26 17:06

Alessandro Pezzato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!