[Interest] Problems with qt_add_qml_module
Ulf Hermann
ulf.hermann at qt.io
Tue Oct 24 16:47:06 CEST 2023
> 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 ?
You are getting this fundamentally wrong. When using qt_add_qml_module
you do not have to call any qmlRegisterType at all. qmltyperegistrar and
CMake do all of this behind the scenes and relieve you from the pain of
maintaining your plugins, type registration calls, qmltypes files,
versions, metaobject revisions and all the other cruft you have to do in
Qt5. You can easily have modules that contain both QML files and
C++-based types now, too.
All you need to do is make sure the resulting modules end up in an
import path that's visible to your application. The easiest way to do
this is place them in directories named by the module URIs (with dots
replaced by directory separators) directly below the application
directory. That is, no directory named "qml" or other shenanigans
between the modules and the application.
More information about the Interest
mailing list