0

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.

Community
  • 1
  • 1
Artem Zefirov
  • 423
  • 5
  • 14

1 Answers1

2

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.
Community
  • 1
  • 1
kefir500
  • 4,184
  • 6
  • 42
  • 48