Path to the project current dir in qt

雨燕双飞 提交于 2019-12-23 05:09:31

问题


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.


回答1:


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.

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.

So, according to your needs:

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


来源:https://stackoverflow.com/questions/43160602/path-to-the-project-current-dir-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!