qt中项目当前目录的路径 [英] Path to the project current dir in qt
问题描述
我想获取 Qt 中项目目录的路径,并引用我项目中相对于它的其他文件.我知道这里已经讨论过这个问题获取 Qt 应用程序中的当前工作目录和这里如何获取Qt的当前工作目录路径申请?但答案仍然未知.如果不可能得到这样的路径,那么在Qt项目的文件之间导航的方法是什么.
I want to get a path to the project directory in Qt and reference the other files of my project relative to it. I know this issue have been already discussed here Get current working directory in a Qt application and here How to get current working directory path of a Qt application? but the answer is still unknown. In case it's impossible to get such a path then what is the approach of navigation among files of the Qt project.
推荐答案
根据您的评论,您正在尝试:
Based on your comment, you are trying to:
访问我的程序中正在使用的一些图像.我当然可以将它们放入构建目标目录,但是将我的代码传递给其他人会变得不舒服.
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 目录的概念混合在一起可能会有用的情况,如果我错了,请纠正我.
The approach to store resource files in the project source directory and rely on such structure at runtime is not a greatest idea. I can't imagine the situation when mixing the concepts of initially decoupled source and build directories could be useful, correct me if I'm wrong.
所以,根据您的需要:
- The most simple and plain way is to use the Qt resource system. The resource files are simply embedded into the executable, so there will be no need to access the file system.
- Another way is the automatic deployment of the needed files. This answer describes the way to copy your files to the target directory using
qmake
.
这篇关于qt中项目当前目录的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!