re-compiling (cached) qml components
-
Please forgive me if I've missed a prior post on this topic.
What must I do to ensure that updated .qml files re-compiled when I try to use them? I assume this is related to how the QML engine caches components, but I need to know how to "force" re-compilation when the essential .qml source files are changed.
I use a Windows 10 platform and the MinGw-64 compiler for C, C++, etc. installed. I routinely use Qt 6, but occasionally need Qt 5, which may be related to my current difficulty.
I am a casual and infrequent user of QML. However, I have a legacy app that requires QtLocation (and a few other) packages that were available in Qt 5 but are not available in Qt 6. The still work fine, but I'd like to tweak the app a bit. I no longer have an installation of QtCreator for Qt5, so cannot really debug the app. That is not directly the problem, because I have always ensured that I can compile and use my apps outside of the Qt environment (I use many 3rd party libraries that are sort of incompatible with Qt).
In any event, changes that I make to .qml files ARE NOT recognized when I run the app that uses them.
What might I be missing?
Thanks for any pointers.
-
@drmhkelley said in re-compiling (cached) qml components:
What must I do to ensure that updated .qml files re-compiled when I try to use them?
Basically, you want ensure that your *.qml files are being managed under the Qt Quick Compiler. This process has changed quite significantly in recent years, so the first questions are:
- What is the exact version of Qt that you're using?
- How are your QML files added to your project?
-
Thank you for the hints - I'll try to figure that out. In the meantime, I'll attempt to answer your questions below.
First, there are three important disclaimers.
-
As only an occasional user of QML there are many aspects of which I have at best a rudimentary understanding - such as proper use of the Qt Quick Compiler. But you've given me a good reason to dig a bit into that.
-
It may be difficult to figure this out if there was significant change between Qt 5 and Qt 6. I no longer have an installation of Qt Creator that uses Qt 5. The app in question relies on the packages such as QtLocation that are not available in Qt 6. So I can probably figure this out for Qt 6, but perhaps not for Qt 5.
-
I typically compile apps outside the Qt environment and just use Qt Creator for debugging purposes.
Now for answers to your specific questions (with my very incomplete understanding of QML)
I use Qt 5, in particular QtLocation and QtPositioning, which were not available for Qt 6.
I add QML files to my project thusly:
-
the .cpp app calls qmlRegisterType<SomeObject> for some locally developed objects.
-
initialize an instance of QQmlApplicationEngine via:
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral(":/imports"));
engine.load(QUrl(QStringLiteral("qrc:///qml/newmap.qml")));I am not quite sure what either method does, but newmap.qml is the main QML module and all of its components exist in the local folder qml.
- newmap.qml explicitly imports all of the required components.
Is this helpful to suggest any specific next steps?
Thanks in advance
-
-
You're welcome.
Rudimentary understanding is not a problem; we're here to learn and teach :-)
@drmhkelley said in re-compiling (cached) qml components:
I use Qt 5
Can you be more specific? IIRC, Qt 5.15 uses the Qt Quick Compiler by default, whereas Qt 5.12 doesn't. Make sure you're using Qt 5.15 unless you have a very good reason to use an older one.
I add QML files to my project thusly:
-
the .cpp app calls qmlRegisterType<SomeObject> for some locally developed objects.
-
initialize an instance of QQmlApplicationEngine via:
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral(":/imports"));
engine.load(QUrl(QStringLiteral("qrc:///qml/newmap.qml")));I am not quite sure what either method does, but newmap.qml is the main QML module and all of its components exist in the local folder qml.
OK, this tells me that your QML files are all managed inside a *.qrc file. That's a good start.
This means each time you modify your *.qml source files, as long as you run your compilation (and as long as your computer's clock is correct), your build system should automatically pack the modified files into your final application.
(But just to double-check: Are ALL of your *.qml files put inside a *.qrc file?)
- I typically compile apps outside the Qt environment and just use Qt Creator for debugging purposes.
qmake or CMake? Can you share your project file (*.pro or CMakeLists.txt)?
I no longer have an installation of Qt Creator that uses Qt 5.
A single installation of Qt Creator can be used to build projects with multiple versions of Qt.
in particular QtLocation and QtPositioning, which were not available for Qt 6.
- Qt Positioning is available: https://doc.qt.io/qt-6/location-positioning-cpp.html
- Qt Location is currently being ported: https://bugreports.qt.io/browse/QTBUG-96795
-
-
Ooops - stopped paying attention for a bit, but thanks very much for the additional imformation.
For your new questions:
-
Version of Qt 5 was Qt 5.15. The app was developed starting with version Qt 4.??, but I kept it going through 5.15.
-
files managed inside a *.qrc file ...
What specifically do you mean by "run your compilation"? Are you referring to the steps I specifically initiate via "make"? Or do you refer to steps taken more indirectly through the QML compilation engine? That's where I start getting pretty confused.
Also, what uses the info in the .qrc file? It is referenced in the .pro file (RESOURCES += ...), but it isn't obvious what is done with that.
-
I don't use either qmake or CMake - never found a "simple" enough explanation/example to figure them out. Instead, I just use mingw32-make, which I've used extensively for many eons.
-
"multiple versions of Qt" with single Qt Creator. When I was first starting to use Qt, I tried to do that, but was never successful. Can you point me to any simple description of how to accomplish that?
-
Many thanks for the pointers to ports of positioning and location to Qt 6. When I first converted to Qt 6, I tried to keep up with that, but stopped once it seemed unlikely to ever reach any sensible stage of utility. I will definitely look more into whether the current status allows users like me to use them productively.
Many thanks
-
-
@drmhkelley said in re-compiling (cached) qml components:
Ooops - stopped paying attention for a bit, but thanks very much for the additional imformation.
No problem.
For your new questions:
- Version of Qt 5 was Qt 5.15. The app was developed starting with version Qt 4.??, but I kept it going through 5.15.
Great!
- files managed inside a *.qrc file ...
What specifically do you mean by "run your compilation"? Are you referring to the steps I specifically initiate via "make"?
I meant "run qmake + make"
Or do you refer to steps taken more indirectly through the QML compilation engine? That's where I start getting pretty confused.
Programmers are not meant to run the QML compiler directly. Most of the time, you don't even have to think about it because qmake and make take care it it for you automatically.
Also, what uses the info in the .qrc file? It is referenced in the .pro file (RESOURCES += ...), but it isn't obvious what is done with that.
- I don't use either qmake or CMake - never found a "simple" enough explanation/example to figure them out. Instead, I just use mingw32-make, which I've used extensively for many eons.
At the core of it, qmake converts your *.pro file into a Makefile. Programmers would run qmake first, then run make. when qmake sees the
RESOURCES += ...
in your *.pro file, it writes the relevant rules into your Makefile to run rcc.exe.Anyway, this might be the source of your problem. rcc.exe reads the *.qrc file, collects the latest version of the resource files, and embeds them into your executable. If you have a *.qml file that isn't listed in the *.qrc file, or if your Makefile does not contain rules to invoke rcc.exe when those files are changed, then that would explain why your modified *.qml files are not getting processed.
If you're running mingw32-make directly but not running qmake, that means your *.pro file is not actually getting used at all. You can probably delete the *.pro file and see no difference.
- "multiple versions of Qt" with single Qt Creator. When I was first starting to use Qt, I tried to do that, but was never successful. Can you point me to any simple description of how to accomplish that?
- Use the Qt Online Installer to install all the versions of Qt that you want (ensure that you have also installed the relevant compilers too)
- Create or open a project in Qt Creator. It will ask you which installed version(s) of Qt you want to use with your project, so make your selection.
- Click the "Run" button to build and run your application with your first selected version of Qt.
- Use the "Kit Selector" to select a different version of Qt, and click the "Run" button to build and run your application with that other version of Qt (see https://doc.qt.io/qtcreator/creator-building-targets.html for the diagram)
That's the gist of it.
- Many thanks for the pointers to ports of positioning and location to Qt 6. When I first converted to Qt 6, I tried to keep up with that, but stopped once it seemed unlikely to ever reach any sensible stage of utility. I will definitely look more into whether the current status allows users like me to use them productively.
Many thanks
👍