QT QML resource files do not recompile after changes

I'm using QT 5.9.1 working on Mac OS. My project is mobile App with C++ logic and QML UI Layer. All QML files are included into qml.qrc file, so in my .pro file I have

RESOURCES += qml.qrc

Inside qml.qrc there is a list of all resource files I use in Project, such as pictures, icons and QML files, in QT Creator it's displayed OK:

List of source files

As you can see some QML files are located in ROOT path of qml.qrc when other files are in subfolders , e.g. "qrc:/Elements/".

So problem is that whenether I make changes in Files that located in root of qml.qrc - they are normally recompiled when I press build, rebuild, or clean and build, so I can see my changes. As a result in my build directory I see that qml_qrc.cpp (as I understand this file contains cpp representation of my resource files and is used to compile them) file is refreshed,my changes are applied and everything is OK.

Here is just piece of this file, which begins with cpp hex representation of MainPage.qml resource file.

/**************************************************************************** ** Resource object code ** ** Created by: The Resource Compiler for Qt version 5.9.1 ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/

static const unsigned char qt_resource_data[] = { // /Users/admin/QtProjects/LazuritApp-temp/MainPage.qml
0x0,0x0,0x7,0xd1, 0x0,
0x0,0x1e,0xbb,0x78,0x9c,0xd5,0x19,0x5d,0x6f,0xdc,0x36,0xf2,0x7d,0x7f,0x5,0x6f, 0xb,0x14,0xbb,0x69,0xa2,0xf5,0xae,0xed,0xa4,0xde,0xa0,0x77,0xf0,0xba,0x49,0x63, 0x20,0x45,0xda,0xda,0x68,0x1e,0xe,0x45,0xc1,0x95,0xa8,0x15,0x2f,0x5a,0x51,0xa5, 0x24,0xdb,0x5b,0xc3,0x40,0xda,0x2,0xed,0x1,0x79,0x28,0x70,0x68,0x71,0xcf,0xf7, 0xf,0xdc,0xbb,0x6b,0x1b,0x34,0x4d,0xfa,0x17,0xb4,0xff,0xa8,0x43,0x52,0x5f,0x94,

..............

But if I change those resource files located in subfolders, qml_qrc.cpp file is not refreshed, so my resource files are not rebuild, even if I try Clean, then rebuild. Even if I do "run qmake" manually and then rebuild. The only thing helps in this situation - to manually delete build folder (or to be more precisely you can just delete qml_qrc.cpp file). So then pressing "Build" will create new qml_qrc.cpp file, which will contain correct code, with changes I've done in my resource files.

Can someone help me or explain why this happens and what can I do in this situation? deleting manually and rebuilding is annoying, but placing all resource files in root path of project is also not a good decision...

I also tried to paste

update qml

qml_scenes.depends = $$PWD/QML Files/OrdersPage.qml

qml_scenes.commands = QMAKE_EXTRA_TARGETS += qml_scenes

as was described here, but it didn't help

Upvotes: 8

Views: 4789

Answers (2)

Matt
Matt

Reputation: 15186

Unfortunately, the solution given in a link provided in the comments seems to be incomplete and/or broken. But it can be done like this:

update_qml.target = qml.qrc
update_qml.commands = echo>>$${update_qml.target} # same as touch
update_qml.depends = $$files(path/to/resource/files/*, true) # recurse into subdirs
QMAKE_EXTRA_TARGETS += update_qml
PRE_TARGETDEPS += $${update_qml.target}

For those who interested in how it works, QMAKE_EXTRA_TARGETS produces the following Makefile rule:

qml.qrc: file1 file2 ...
        echo>>qml.qrc

So issuing a command make qml.qrc will update the timestamp of qml.qrc as needed. However, to save us from manual typing it every time, we also make use of PRE_TARGETDEPS which fixes the main building rule:

$(DESTDIR_TARGET): qml.qrc $(OBJECTS) and other stuff ...
        $(LINKER) flags objects and other stuff ...

So now make utility will scan the previous rule every time while building the target.

Upvotes: 0

ok, after hours of digging in QTBUGS traces, stackoverflow and others forums I found solution, which somehow satisfies me..

1) Create script file (for me it's .sh file as I working on MAS OS, for Windows it will be .bat file) with "touch" command to qml.qrc file. In my case it contains 2 lines :

#!/bin/sh

Touch qml.qrc

2) Add Custom build step (Projects->Build Settings->Build Steps->Add Custom Process Step). Choose your created .sh file, choose working directory when you build is located. Make this custom step to be the first executed (before qmake and Make)

3)So, now changes in qml resource files will be compiled every time you build the project. Script will firstly touch our qml.qrc file, which will refresh it's modified date, so that qml.qrc (hence, our qml resources too) will be added to makefile dependencies.

it seems to be pretty rough way to solve the problem, but at least you don't have to Clean, Rebuild and so on..

If someone have better solution, please let me know)

Upvotes: 5

Related Questions