I have a project I am working on with Qt Creator and I'm trying to get it to add my resource files to my build directories (output) automatically. I have the files in the project directory, but I don't know how to edit the *.pro file to make it include additional content files. (If that is even possible?)
Does anyone know how to get content files exactly as they are into my output directories?
EDIT:
Just so everyone knows exactly what I'm trying to do... I want to automatically copy FFmpeg as an executable into my build directories. That way if the build output does not exist, it will be copied over just before the application is debugged.
I'm trying to prevent clean operations from wiping out resources and me having to copy them back over again and again. Also... I work on multiple computers and use either SVN or Dropbox, so I want to keep my paths relative. They will change when I move from one computer to another.
FINAL ANSWER:
CONFIG(release, debug|release) {
DESTDIR = release
} else {
DESTDIR = debug
}
#for Windows
win32 {
#in Windows, you can use & to separate commands
copyfiles.commands += @echo NOW COPYING ADDITIONAL FILE(S) &
copyfiles.commands += @call copy ..\\$${TARGET}\\ffmpeg.exe $${DESTDIR}\\ffmpeg.exe
}
#for Mac
macx {
#commands would go here if I had them
}
QMAKE_EXTRA_TARGETS += copyfiles
POST_TARGETDEPS += copyfiles
In the Location field, specify a location for the file. Select Add to create a . qrc file and to open it in the Qt Resource Editor. To add resources to the file, select Add > Add Files.
Using Qt Creator. Just create a file with . qrc extension and add that. I created a file named np. qrc that has the code you provided and loaded in to resource but there is no prefix created.
In the Qt Creator application, choose menu File->Open File or Project, navigate to the project folder and choose the . pro file to open.
The rcc tool is used to embed resources into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (. qrc) file.
If you want to automatically copy files into a directory after the build you can use a post build target.
In your pro file:
win32 {
copyfiles.commands = @call copy <from> <to>
}
macx {
copyfiles.commands = cp <from> <to>
}
QMAKE_EXTRA_TARGETS += copyfiles
POST_TARGETDEPS += copyfiles
Instead of copy <from> <to>
you can obviously call a script/batch file that does more post build steps.
Check out the Qt Resource System.
To add the resource file into your project, you have add the following in your .pro
file..
RESOURCES = application.qrc
Detailed examples available in the Qt Docs..
Once added into the pro file, a separate .qrc
file will be added into your Qt project with which you can double click and add your desired resources like icons, translation files etc.,
Hope it helps..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With