Search code examples
qtfilesizeqthreadqfileinfo

Get file size during generate in QT


I need get the File size while it is being generated.

I've tried using QThread and QFileInfo::size and a while with a flag that signals when the finished file, but the value never changes.

So was wondering if you can take the file size while it is being generated.


Solution

  • From the Qt docs:

    Note: To speed up performance, QFileInfo caches information about the file. Because files can be changed by other users or programs, or even by other parts of the same program, there is a function that refreshes the file information: refresh(). If you want to switch off a QFileInfo's caching and force it to access the file system every time you request information from it call setCaching(false).

    So try the QFileInfo::refresh() function before (re-)checking the file size.