qt中项目当前目录的路径 [英] Path to the project current dir in qt

查看:53
本文介绍了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.

将资源文件存储在项目源目录中并且在运行时依赖这种结构的方法并不是一个好主意.我无法想象将最初解耦的 sourcebuild 目录的概念混合在一起可能会有用的情况,如果我错了,请纠正我.

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.

所以,根据您的需要:

  • 最简单明了的方法是使用Qt资源系统.资源文件只是嵌入到可执行文件中,因此无需访问文件系统.
  • 另一种方式是自动部署所需文件.这个答案描述了使用 qmake 将文件复制到目标目录的方法.
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆