Variable that refers to the project directory in Qt Creator?

非 Y 不嫁゛ 提交于 2019-12-03 17:09:41

问题


I'm working on a cross-platform Qt application and the paths are different on Mac OS X and Windows. Since the project is on an external hard-drive, the drive letter also occasionally changes on Windows.

For that reason, I would like to refer to the project directory using a variable, preferably a built-in one. In particular, is there such a variable usable in:

  • The .pro file?
  • The build settings (in the Projects tab)?

回答1:


The built-in _PRO_FILE_PWD_ variable contains the path to the directory containing the project file in use. That variable may be useful for you.




回答2:


To complete, @Bill's answer, the way to refer to the source path in the Build Settings is to use %{sourceDir}.

%{buildDir} is also available.




回答3:


Since I struggled a bit to find it, I'm adding it here.

In addition to %{sourceDir} and %{buildDir}, you could use %{CurrentDocument:Path}, %{CurrentDocument:FilePath} and %{CurrentProject:Path} to refer to specific files and folders in the project directory.




回答4:


There are problems with $$_PRO_FILE_PWD_ on windows, because it contains forward slash allways. You need to fix slash using shell_path.

 $$shell_path($$_PRO_FILE_PWD_)


来源:https://stackoverflow.com/questions/12106502/variable-that-refers-to-the-project-directory-in-qt-creator

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