When running the this sample code from QFileInfo documentation:
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = "archive"
Would it result in accesses to the file system?
I'm assuming that calling fi.lastModified()
or fi.exists()
would require the file system to be accessed, but what about it I only use it to extract parts of the file name (extension, base file name, only the directory, etc.)?
Without looking at the implementation of methods it is hard to say precisely which method access the filesystem and which not. But I found in the library this sort of explanation that answer your question:
Performance Issues
Some of
QFileInfo
's functions query the file system, but for performance reasons, some functions only operate on the file name itself. For example: To return the absolute path of a relative file name,absolutePath()
has to query the file system. Thepath()
function, however, can work on the file name directly, and so it is faster.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 aQFileInfo
's caching and force it to access the file system every time you request information from it callsetCaching(false)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With