Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does constructing a QFileInfo object result in file system accesses?

Tags:

c++

qt

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

like image 243
sashoalm Avatar asked Feb 18 '23 06:02

sashoalm


1 Answers

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. The path() 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 a QFileInfo's caching and force it to access the file system every time you request information from it call setCaching(false).

like image 136
andrea.marangoni Avatar answered Apr 29 '23 19:04

andrea.marangoni