gpt4 book ai didi

c++ - 构造 QFileInfo 对象会导致文件系统访问吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:17 24 4
gpt4 key购买 nike

运行 QFileInfo 文档中的示例代码时:

 QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = "archive"

它会导致对文件系统的访问吗?

我假设调用 fi.lastModified()fi.exists() 需要访问文件系统,但我只使用它呢它提取部分文件名(扩展名、基本文件名、仅目录等)?

最佳答案

如果不查看方法的实现,就很难准确地说出哪个方法访问文件系统,哪个不访问文件系统。但是我在图书馆找到了回答你问题的这种解释:

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

关于c++ - 构造 QFileInfo 对象会导致文件系统访问吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13724744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com