Quick Compiler resources are not visible
-
I have a project with some resources. There is a problem when I am trying to load main screen from qml file.
Resources are add as follows:
RESOURCES += \ ... \ source/core/QmlFiles_ScreenBase.qrc \ ...
Then file is loaded as follows
auto* engine = new QQmlApplicationEngine; engine->load(QUrl(QStringLiteral("qrc:///ui/qml/screens/MainScreen.qml")));
If I use
CONFIG+=qtquickcompiler
, there are couple things generated under the hood
Info: qrc files that contains some interesting resources is calledQmlFiles_ScreenBase.qrc
- after running qmake - in main build directory there is a new file
source_core_QmlFiles_ScreenBase_qmlcache.qrc
which contains nothing except qmldir entry - at some point cachegen is generating file
source_core_ui_qml_screens_MainScreen_qml.cpp
which contains some data and it is generated from existing qml file - Compiler produces
obj/source_core_ui_qml_screens_MainScreen_qml.o
- Linker generates application
However if I try to run application only thing that is displayed is
qrc:/ui/qml/screens/MainScreen.qml:-1 No such file or directory
I tried to list resources that are available during runtime and nothing from that qrc file is listed. Contents from some other qrc files are not listed as well.
Rebuilding or changing to Debug configuration does not fix anything. I tried to move file to other module and build application once again and suddenly it is working (resources are listed).
- qml cache file is not generated for new module
- cpp file is generated by cachegen (identical as in previous case, except internal naming)
- Compiler produce object file
- Linker is producing app file
I could also turn off quick compiler, but this is not an option.
I want to ask how to use quick compiler and build it correctly at the first time?
- after running qmake - in main build directory there is a new file
-
@Jarek-B said in Quick Compiler resources are not visible:
qtquickcompiler
Have you take a look at documentation? ==> https://doc.qt.io/qt-5/qtquick-deployment.html#managing-resource-files-with-the-qt-resource-system
I think you are not using the right path to access main.qml.
According to your code extract, QmlFiles_ScreenBase.qrc should looks like:<!DOCTYPE RCC> <RCC version="1.0"> <qresource prefix="/"> <file>ui/qml/main.qml</file> </qresource> </RCC>
And the path structure as follow
source/core |- QmlFiles_ScreenBase.qrc |- ui |- qml |-main.qml
Is this the case?
-
After moving a file to separate module I changed a name to main.qml from MainScreen.qml, but I forgot to update post text. Moreover if I do not use qtquickcompiler everything works like a charm, and finally there is a question: why some other resources are gone?
This is how I am listing themQDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next(); }
Result without QuickCompiler
":/ui/qml/screens" ":/ui/qml/screens/qmldir" ":/ui/qml/screens/FullScreen.qml" ":/ui/qml/screens/ScreenManager.qml" ":/ui/qml/screens/BaseScreen.qml" ":/ui/qml/screens/MessageBoxScreen.qml" ":/ui/qml/screens/MessageBoxScreenForm.qml" ":/ui/qml/screens/StandardScreen.qml" ":/ui/qml/screens/MessageBox.js" ":/ui/qml/main.qml"
Result with QuickCompiler
":/ui/qml/screens" ":/ui/qml/screens/qmldir"
-
@Jarek-B I don't know what is your directory structure, this is how I would do:
QmlFiles_ScreenBase.qrc |- ui |- qml |-main.qml |- screens |- qmldir |-FullScreen.qml |-...
And the resources file as follow:
<!DOCTYPE RCC> <RCC version="1.0"> <qresource prefix="/ui/qml"> <file alias="main.qml">ui/qml/main.qml</file> </qresource> <qresource prefix="/ui/qml/screens"> <file alias="qmldir">ui/qml/screens/qmldir</file> <file alias="FullScreen.qml">ui/qml/screens/FullScreen.qml</file> ... </qresource> </RCC>
-
I found out that between two cases (working and not working one) only file that differs substantially is
qmlcache_loader.cpp
. In non-working case it was over 5 times smaller than normally, and that's because 80% of all resources were not there.Now, the only reason why it's happened is because some qrc files has been added to
RESOURCES
twice, and only those resources were available at the end.
Why it worked after moving file from one qrc file to another? Probably because only those part of the project which depends on that two files has been updated and though every qrc file has been included only once (duplicates was in my case in the other part of the project).EDIT:
Before marking it as solved I will try to confirm all of the above hypothesis.