Utils::FileInProjectFinder Class
class Utils::FileInProjectFinderFileInProjectFinder 类是一个辅助类,用于根据给定的文件 URL 在项目目录中查找原始文件。更多内容...
| Header: | #include <FileInProjectFinder> |
公共函数
| Utils::FilePaths | findFile(const QUrl &fileUrl, bool *success = nullptr) const |
详细说明
在构建和部署过程中,文件通常会被复制。findFile() 会根据给定的文件路径,在项目目录中搜索现有文件。
例如,以下文件路径都应映射到 $PROJECTDIR/qml/app/main.qml:
- C:/app-build-desktop/qml/app/main.qml(影子构建目录)
- /Users/x/app-build-desktop/App.app/Contents/Resources/qml/App/main.qml(macOS 上的文件夹)
成员函数文档
Utils::FilePaths FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success = nullptr) const
返回项目目录中与文件 URLfileUrl 最匹配的文件。
该函数首先检查项目目录中是否存在该文件。如果不存在,则去除路径中的首级目录,然后检查这个(现在更短的)路径是否存在,依此类推。其次,它尝试在指定的 sysroot 文件夹中查找该文件。 第三,它遍历项目文件列表,并在其中搜索文件名匹配项。
如果所有尝试均失败,该函数将返回文件 URL 中的原始路径。为表明在项目中未找到匹配项,success 将被设置为 false。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.