[Interest] Problems with qt_add_qml_module

Stefan Seefeld stefan at seefeld.name
Tue Oct 24 16:34:48 CEST 2023


On Tue, Oct 24, 2023 at 10:11 AM Ulf Hermann <ulf.hermann at qt.io> wrote:

> > Most of the context would be injected into the QML runtime from C++ via
> > calls to `setContextProperty()`, as well as by defining additional QML
> > modules from C++ (via `qmlRegister...()`).
>
> This is where your architecture fails. By using setContextProperty() and
> procedurally registering types, you
>
> a, still make your types depend on the context (due to context
> properties). You still won't be able to use them in standalone tools.
>
> b, prevent QML tooling such as qmllint, qmlcachegen, qmlls to do
> anything useful with your QML code since they cannot see through your
> procedural type registrations or your context properties.
>

This is precisely what I'm saying, and why I want to define my types in an
extension module.



>
> Instead of this:
>
> 1. Use singletons or object properties instead of context properties.
> There are also initial properties you can pass to QQmlComponent and
> QQmlApplicationEngine if that helps.
>
> 2. Use QML_ELEMENT and friends as well as qt_add_qml_module in CMake to
> define your types declaratively so that tooling can see them.
>

Yes !!! Thank you for confirming that I'm on the right track ! :-)



> This way you obtain truly re-usable QML modules you can test in
> isolation. You also won't need to implement your own plugins or fight
> with the linker since qmltyperegistrar will generate the registration
> code and the hacky symbol references for you. This is the whole point of
> qt_add_qml_module. If you don't want qmltyperegistrar to do its work,
> there is little point in using qt_add_qml_module at all.
>

So it sounds like I still don't understand what `qt_add_qml_module` is
doing.

In our existing code we call `qmlRegisterType<...>(...)` in our regular C++
code (e.g., some shared libraries that the main application links to).
I thought that, to be able to use those types in stand-alone QML code, I'd
need to move these calls into plugins, or at least have some QML extension
module link to these libraries so they can see these types. What am I
missing ?

 Thanks,


-- 

      ...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231024/14224707/attachment.htm>


More information about the Interest mailing list