将文件复制到 Qt Creator 中的目标目录
我想将数据文件从源树中的目录复制到链接应用程序的目录,以便它在运行时可用(仅在 Windows 上)。似乎有两种建议的技术:使用后目标依赖项来发出 DOS 复制命令(在 Qt Creator 构建目录中包含资源文件)或使用安装步骤(编译项目后将文件复制到构建目录与 Qt),但我无法按照我想要的方式工作。
前者要求我使用 qmake 路径变量来生成源路径和目标路径,但它们包含反斜杠路径分隔符,DOS 复制命令无法处理。
安装解决方案强制我的项目的其他用户在 Qt Creator 运行之前设置一个构建后步骤(事实上,每个配置一个),我想避免这种情况,因为我想让我的项目使用默认值Qt Creator 安装。
有没有什么方法可以完成这个看似简单的任务,并且可以在项目的 .pro 文件中完全定义?例如,有没有一种方法可以以特定于平台的方式扩展 qmake 路径变量?
I want to copy a data file from a directory in my source tree to the directory of the linked app so it's available at runtime, on Windows only. There appear to be two suggested techniques: use a post target dependency to issue a DOS copy command (Including resource files in Qt Creator build directory) or use an install step (Copy a file to the build directory after compiling project with Qt), but I cannot make either work in the way I would like.
The former requires me to use qmake path variables to generate my source and destination paths, but they contain backslash path separators, which the DOS copy command cannot handle.
The install solution forces other users of my project to set up a post build step in Qt Creator before it will work (one per configuration, in fact) and I would like to avoid this, as I want to make my project work with a default Qt Creator installation.
Is there any way to do this apparently simple task that can be wholly defined in the .pro file for the project? For example, is there a way to expand qmake path variables in a platform specific way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管这些命令仅在实际链接可执行文件后运行,但此解决方案不需要外部批处理文件。注意:这是仅限 Windows 的解决方案:
从我们的 .pri 文件:
这会在 Makefile 中放置一条命令,将 MyLibs/x64 或 MyLibs/Win32 中的所有 .dll 文件复制到目标目录中。
但是,如果不需要链接可执行文件,则不会复制 .dll。
构建后批处理文件不会有此限制。
Though these commands run ONLY after the executable is ACTUALLY linked, this solution doesn't require an external batch file. Note: this a Windows-only solution:
From our .pri file:
This places a command in the Makefile that copies all the .dll files in MyLibs/x64 or MyLibs/Win32 into the destination directory.
However, if the executable did not need to be linked, then the .dlls are NOT copied.
The post build batch file would not have this limitation.
解决此问题的一种方法是调用外部批处理文件并在其中执行分隔符替换:
One way to solve this, is by calling an external batch file and performing the separator substitution in there: