Copy file to destination directory in Qt Creator

I want to copy a data file from a directory to the source tree in the directory of the associated application so that it is available at run time, only on Windows. There seem to be two suggested methods: use a post dependency to issue a DOS copy command ( Including resource files in the Qt Creator build directory ) or use the installation step ( Copy the file to the build directory after compiling the project with Qt ), but I can't get it working as we would like.

The first requires me to use qmake path variables to generate my source and destination paths, but they contain backslash path separators that the DOS copy command cannot handle.

The installation solution forces other users of my project to configure the post-build step in Qt Creator before it works (one for each configuration), and I would like to avoid this, because I want my work on the project to install by default is qt creator.

Is there a way to do this seemingly simple task that can be fully defined in a .pro file for a project? For example, is there a way to extend qmake path variables in a specific way on the platform?

+2
qt qt-creator
source share
1 answer

Although these commands are run ONLY after the ACTUALLY linked executable, this solution does not require an external batch file. Note: this is a solution for Windows:

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), /, \\)} ... } 

This places the command in the Makefile, which copies all the DLL files in MyLibs / x64 or MyLibs / Win32 to the target directory.

However, if the executable does not need to be linked, then .dlls are NOT copied. The post build batch file will not have this limitation.

+1
source share

All Articles