Copy file at build time in Qt creator.
-
hi, I'm creating an application with QT Creator.
I need to copy a file to the destination folder after compiling.
I searched the internet, but I don't found any clear guides, and most say to add dozens of lines to the .pro file.
I should simply copy a file from the source folder to the folder that contains the executable.I tried adding a "build step" in QT Creator, look at the screenshot but it doesn't work
Can anyone help me?
Thanks in advantage.PS: I would need a multi-platform solution.
-
Hi,
Technically, that copy file custom step is what you can do in your .pro file as a post build step.
-
@SGaist OK, but it don't work. What's the correct way to create a copy file custom build step?
-
@federico.massimi Neither $COPY_FILE nor $$PWD are valid Qt Creator variables. The A -> B button opens a dialog where you can choose variables.
-
@aha_1980 said in Copy file at build time in Qt creator.:
OK, I found correct variable for source path (%{sourceDir}) and build directory (%{buildDir}), but I found nothing about the copy command.
I've seen this post:
https://stackoverflow.com/questions/20324061/where-are-variables-such-as-mkdir-and-copy-dir-defined
but it seems deprecated now.
Currently, what is the copy command MACRO to be inserted in the custom build step? -
@federico.massimi said in Copy file at build time in Qt creator.:
Currently, what is the copy command MACRO to be inserted in the custom build step?
There is no such macro.
-
@federico.massimi you can call whatever command you like to call, for example
copy
. I'm no sure if I understand your question. -
@aha_1980
Yes, ok, I realized that I can use any command, I'm asking if a macro existed in order to be multiplatform.
Otherwise I have to create a QT creator project in which I put the copy command for Linux, a QT creator project in which I put the copy command for Windows etc etc.But from what I understand there is no macro to create a multiplatform copy command. Right?
-
@federico.massimi said in Copy file at build time in Qt creator.:
But from what I understand there is no macro to create a multiplatform copy command. Right?
Correct.
But that would not help, anyway. Everything you put in these custom build step fields is local to your machine. If you want these actions to happen on each machine your project is running, you have to put appropriate commands into your .pro file.
-
Hi, for me the best ever solution for copy files on build is using file_copies.prf.
You may find example of usage in that answer on SOF:Qt 5.6 added this as an undocumented feature:
CONFIG += file_copies
Invent a name to describe the files you want to copy:
COPIES += myDocumentation
List the files that you want to copy, in its .files member:
myDocumentation.files = $$files(text/docs/*.txt)
Specify the destination path in the .path member:
myDocumentation.path = $$OUT_PWD/documentation
Optionally specify a base path to be trimmed from the source paths:
myDocumentation.base = $$PWD/text/docs
It basically works by doing the same things as many of the other answers here. See file_copies.prf for the gory details.
The interface is very similar to that for INSTALLS.
I tested it on Windows and Linux. And with nested directories too.
-
This post is deleted!