[Interest] qt_add_qml_module and not embedding QML files

Ulf Hermann ulf.hermann at qt.io
Mon Oct 31 10:48:07 CET 2022


> Is there a way to not embed QML files into the Qt resource system when 
> using qt_add_qml_module() ?

We can only pre-compile files embedded into the resource file with 
qmlcachegen. That's why we strongly recommend using the resource file 
system. You can, of course still manually write your qmldir files and 
handle the build process manually like in Qt5. It's definitely not 
recommended, though.

> Or at least, not generate the "prefer :/..." line in the qmldir file ?

The "prefer" line is vital. If you drop it, the module still looks like 
it would use the pre-compiled code in the qrc system with all the nice 
optimizations you get from compiling functions and bindings to C++. Yet, 
the QML engine will actually load the files from the host file system 
and ignore all of the goodies. Don't do this.

> Having the prefer line makes it impossible to load QML files from disk, 
> preventing any kind of live reloading of QML.

If you're using Qt Creator's "QML preview" feature, it should try to 
match your qrc paths to the source paths in your project. As the engine 
then runs in debug mode, it can live-replace the contents of the QML 
files. There is also a command line "qmlpreview" tool.

If the QML preview feature somehow got broken in Qt6, please file a bug 
report. It is mostly used by Qt Design Studio, and Qt Design Studio 
likes to use "qmlproject" projects without cmake.

best regards,
Ulf


More information about the Interest mailing list