Copying non-resource files with QMake for easier debugging

When it comes to Qt Quick and QML based apps, the standard seems to be to compile all QML and, e.g., image files into a Qt Resource (qrc) file.  This works great (and not just for Qt Quick apps), but what if you need to be able to swap out, e.g. .png’s without recompiling?

I recently ran into a situation where this was indeed necessary and, although deploying the app for Windows (the specific use case under consideration here) isn’t remarkably difficult (thanks to the windeployqt tool), debugging the application with Qt Creator turned out to be a bit tricky.  I was forced to copy the relevant qml files etc to the debug folder whenever I made any changes and this quickly became rather tedious not to mention error prone.

Fortunately, it turns out that QMake steps up yet again through QMAKE_POST_LINK.  It was a simply matter of assigning the required xcopy command (remember, we’re on Windows) to this QMake variable in my .pro file and QMake took care of the rest.

Note: All my QML resources live in a “qml” directory, so take care to adapt the following snippet to your needs. 

# Copies all the qml content to the output directory
# in order to allow for debugging, etc from within QtCreator
CONFIG(release, debug|release) {
    DESTDIR = $$OUT_PWD/release
} else {
    DESTDIR = $$OUT_PWD/debug

win32 {
    command = $$quote($$PWD/qml $$DESTDIR/qml)
    command = $$replace(command, /, $$QMAKE_DIR_SEP)
    QMAKE_POST_LINK += xcopy $$command /s /y /i

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s