[Interest] qt_add_qml_module and not embedding QML files

Benjamin TERRIER b.terrier at gmail.com
Sun Oct 30 19:02:26 CET 2022


On Sat, 29 Oct 2022 at 12:13, Benjamin B (BBenj) <balga.benjamin at gmail.com>
wrote:

> Hello,
>
> I can't answer your question specifically, but if you're using Qt 6 you
> may want to look into QQmlEngine::addUrlInterceptor to handle live reloads.
>  I don't think Qt 5 has something equivalent.
>

Qt 5 had QQmlEngine::setUrlInterceptor().
It seems undocumented, but the class QQmlAbstractUrlInterceptor was
documented.


> You can look for runtimeqml on GitHub for a use of it (disclaimer- I'm the
> author and while it works for me it was not extensively tested ;-)
> https://github.com/GIPdA/runtimeqml ).
>
>
Remapping all qrc files to the filesystem path seems a bit overkill when
using qt_add_qml_module() as we already have a perfectly good on disk QML
module that the engine can use.
Also in this case the qrc files are generated by CMake, I am not sure I can
easily get the names of the qrc files.

In the ends it is really just the "prefer" line in the qmldir that makes it
impossible to use the on disk qml modules.
For now I've found a solution, I just run a "sed" command to comment the
"prefer" line in all the qmldir at the end of CMake configuration. It's a
bit ugly though, I would prefer to set an option in qt_add_qml_module().

Side note, I've also found that the URL interceptor does not work when QML
files are compiled with cachegen (which is the default when using
qt_add_qml_module).
I guess that is because the components are always in cache and the QML
engine never needs to load them by URL.

Cheers
Benjamin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20221030/72034d15/attachment.htm>


More information about the Interest mailing list