qt中项目当前目录的路径
Path to the project current dir in qt
我想在 Qt 中获取项目目录的路径并引用我的项目的其他相关文件。我知道这个问题已经在这里讨论过了
Get current working directory in a Qt application
和这里
How to get current working directory path of a Qt application?
但答案仍然未知。如果无法获得这样的路径,那么在 Qt 项目的文件之间导航的方法是什么。
根据您的评论,您正在尝试:
Access some images which are being used in my program. I could of course put them into build target directory, but it becomes uncomfortable to pass my code to others.
将资源文件存储在项目源目录中的方法和在运行时依赖这种结构并不是一个好主意。我无法想象混合最初解耦的 source 和 build 目录的概念可能有用的情况,如果我错了请纠正我。
所以,根据您的需要:
- 最简单明了的方法就是使用Qt resource system。资源文件简单地嵌入到可执行文件中,因此无需访问文件系统。
- 另一种方式是自动部署所需的文件。 This answer描述了使用
qmake
将文件复制到目标目录的方法。
我想在 Qt 中获取项目目录的路径并引用我的项目的其他相关文件。我知道这个问题已经在这里讨论过了 Get current working directory in a Qt application 和这里 How to get current working directory path of a Qt application? 但答案仍然未知。如果无法获得这样的路径,那么在 Qt 项目的文件之间导航的方法是什么。
根据您的评论,您正在尝试:
Access some images which are being used in my program. I could of course put them into build target directory, but it becomes uncomfortable to pass my code to others.
将资源文件存储在项目源目录中的方法和在运行时依赖这种结构并不是一个好主意。我无法想象混合最初解耦的 source 和 build 目录的概念可能有用的情况,如果我错了请纠正我。
所以,根据您的需要:
- 最简单明了的方法就是使用Qt resource system。资源文件简单地嵌入到可执行文件中,因此无需访问文件系统。
- 另一种方式是自动部署所需的文件。 This answer描述了使用
qmake
将文件复制到目标目录的方法。