How to execute shell command after compile finished from .pro in QT?

What changes must I make to the .pro file if I want to execute chmod command, execute the output binary file, or do some other operations.


I had a similar problem. I wanted a special tool (versioner) to run over the code every time the Makefile was executed. Here's the solution:

(to be read in the Qmake Manual, Configuring qmake's Environment, Section: Customizing Makefile Output)

Create you own Makefile target. Specify the command etc. = .buildfile
mytarget.commands = touch $$


This way, you have an extra target you can call with make mytarget for example. If you want to tie it together to the actual buildtarget you'll have to add:


Hope that helps.

Best regards D

If you are using Qt Creator, you can add custom build steps in the Projects panel:

The right answer depends on exactly what you want, and when. However, as seen in some previously posted comments here QMAKE_POST_LINK is probably what you want rather than POST_TARGETDEPS.

Check out this related post: QMake: execute script after build

For one, when you use POST_TARGETDEPS that fires off BEFORE your exe is created (in Windows) or BEFORE it is recreated (in Linux)! QMake works differently depending upon the platform and the complier.

I needed to do some "symbols processing" on an exe when it was recompiled. POST_TARGETDEPS gave me problems in both Windows (using mingw) and Linux (using gcc). In Windows, it executed my script prematurely, and in Linux it overwrote my exe after I had modified it (i.e. added back my debugging info to the exe after I had stripped it in my external script). QMAKE_POST_LINK worked perfectly, however, in both cases. It's also short, sweet, and more clear by comparison!

Another way to make things in given order is to use empty "super" target:

super.depends = target_pre first target_post

Where first - is default qmake target, and target_pre and target_post some custom targets. Now make super just do the thing.

EDIT: looks like in last versions of Qt build of dependencies is running in paralell so this solution wouldn't work.

Need Your Help

Java not garbage collecting memory

java performance memory garbage-collection

I am reading a very large file and extracting some small portions of text from each line. However at the end of the operation, I am left with very little memory to work with. It seems that the garb...

Changing font in PDF produced by rmarkdown

r pdf latex yaml r-markdown

I am producing reports using rmarkdown. When knitting a PDF