将文件复制到 Qt Creator 中的目标目录 [英] Copy file to destination directory in Qt Creator

查看:63
本文介绍了将文件复制到 Qt Creator 中的目标目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据文件从我的源树中的目录复制到链接应用程序的目录,以便它在运行时可用,仅在 Windows 上可用.似乎有两种建议的技术:使用后目标依赖来发出 DOS 复制命令(在 Qt Creator 构建目录中包含资源文件)或使用安装步骤(使用 Qt 编译项目后将文件复制到构建目录),但我无法按照我想要的方式进行任何工作.

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.

前者要求我使用 qmake 路径变量来生成我的源路径和目标路径,但它们包含反斜杠路径分隔符,DOS 复制命令无法处理.

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.

安装解决方案强制我的项目的其他用户在 Qt Creator 工作之前在 Qt Creator 中设置一个后期构建步骤(实际上每个配置一个),我想避免这种情况,因为我想让我的项目工作使用默认的 Qt Creator 安装.

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.

有什么方法可以完成这个看似简单的任务,可以在项目的 .pro 文件中完全定义?例如,有没有办法以特定于平台的方式扩展qmake路径变量?

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?

推荐答案

虽然这些命令仅在可执行文件实际链接后运行,但此解决方案不需要外部批处理文件.注意:这是一个仅限 Windows 的解决方案:

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:

来自我们的 .pri 文件:

From our .pri file:

win32 {
...
# Copy the appropriate dll files into the target destination directory.

QMAKE_TBB_LIBDIR = $$quote($$PWD/MySource/MyLibs/$${PLATFORM_NAME}/vc9)

QMAKE_POST_LINK = copy /y $${replace(QMAKE_TBB_LIBDIR, /, \\)}\\*.dll > $${replace($$quote(DESTDIR), /, \\)}
...
}

这会在 Makefile 中放置一个命令,将 MyLibs/x64 或 MyLibs/Win32 中的所有 .dll 文件复制到目标目录中.

This places a command in the Makefile that copies all the .dll files in MyLibs/x64 or MyLibs/Win32 into the destination directory.

但是,如果不需要链接可执行文件,则不会复制 .dll.后构建批处理文件没有这个限制.

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.

这篇关于将文件复制到 Qt Creator 中的目标目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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