QT编程中用于查找特定类型文件(例如:*.cpp)的函数是什么?
我需要在电脑上查找特定类型的文件。谁能给我一个可以用来查找系统文件的函数的名称?
I need to find particular type of file on the PC. Can anyone give me the name of a function which I can use to find the system files ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要 QDir 类 和/或 QFileInfo 类。您想要对这些对象使用什么方法取决于您想要做什么以及如何做。
You probably want either the QDir class and/or the QFileInfo class. What method(s) you want to use on those objects depends on exactly what it is you want to do and how you want to do it.
您可以尝试在 QDir 中使用 setSearchPaths 方法。取决于您要寻找什么。
“Qt 使用此搜索路径来查找具有已知前缀的文件。”
You could try using the setSearchPaths method in QDir. Depends on what you're looking for.
"Qt uses this search path to locate files with a known prefix."
Qt 提供了一个 QDirIterator ,其带有
QDir::文件| QDir::NoSymLinks
和QDirIterator::Subdirectories
标志可用于迭代每个项目,如有必要,可获取.fileInfo().completeSuffix()
或.fileInfo().suffix()
(根据需要)检查扩展名类型(“cpp” - 无点),并对文件执行您想要的操作。Qt provides a QDirIterator which with the
QDir::Files | QDir::NoSymLinks
and theQDirIterator::Subdirectories
flags you can use to iterate over each item, if necessary getting.fileInfo().completeSuffix()
or.fileInfo().suffix()
(as desired) to check the extension type ("cpp" - no dot), and do with the file what you will.