Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 896
Алексей Юхин Avatar asked Dec 15 '17 07:12

Алексей Юхин


People also ask

How is QML compiled?

QML and JavaScript code can be compiled into native C++ binaries with the Qt Quick Compiler. Alternatively there is a QML cache file format which stores a compiled version of QML dynamically for faster startup the next time it is run.

What is difference between Qt and QML?

Qt is a powerful time-saving solution for GUI and app creation, especially when it is necessary to combine the efforts of UI/UX and development teams. The QML programming language is often associated with Qt development. Qt can be used for desktop, embedded, and mobile development on multiple platforms.

How do I edit a QML file?

In Projects, double-click a . qml file to open it in the code editor. Then select the Design mode to edit the file in the visual editor.

What is a Qt resource file?

The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.


1 Answers

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)

like image 169
Алексей Юхин Avatar answered Sep 18 '22 23:09

Алексей Юхин