views:

74

answers:

2

Hello,

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
+2  A: 

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.

Wolfgang Plaschg
Can <from> and <to> be relative? Do you have an example of that?
jocull
Of course. The executed command is just an ordinary shell command that's executed relative to your working directory.
Wolfgang Plaschg
If you don't need the resources until deployment or packaging time, you can also add extra INSTALL rules to the .pro file.
andref
I've had trouble getting this to work. The command doesn't seem to know what directory it's in, and the slashes come out the wrong way from variables like $${OUT_PWD} which makes Windows confused.
jocull
But you got it to work in the end?
Wolfgang Plaschg
Also, these commands seem to be ignored when compiling in Qt Creator. I tried setting copyfiles.target = FORCE, but that threw an error.
jocull
No, I haven't ever gotten it to work.
jocull
Sorry, there was a typo: It's copyfiles.command**s**! Take a look at this gist: https://gist.github.com/956d08bfa5236e1a4010. I made a micro project where you can try the post build.
Wolfgang Plaschg
Ahh! I finally have it working (on Windows at least). I will edit my original post with the final answer. Thank you!
jocull
A: 

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..

liaK
Aren't these resources compiled into the output, though? I have things like external processes (*.exe files) that I need to be accessible in the same directory as my compiled output.
jocull