[Interest] [Qt6] QML automatic type registration in a (shared) library
Ulf Hermann
ulf.hermann at qt.io
Fri Jan 14 17:09:04 CET 2022
> Perhaps that's how it's supposed to work, but I'm not intending to mess
> around with the target output paths in cmake. It simply makes no sense
> to me.
If you want the QML engine to find your module, you need to follow
certain conventions around the paths.
You can create a separate CMake target just for your QML module if you
like that better. Then you don't have to mess with the existing target's
output path.
By far the easiest way to deal with all this is keeping the QML modules
in directories named by their URIs already in the source tree. Then it
will just work automatically.
> extern void Q_DECL_IMPORT qml_register_types_Tsc_Ui();
> qml_register_types_Tsc_Ui();
You should _not_ manually call the type registration. This is private
API and it _will_ break.
> So is this the "correct" way to do it with my setup with NO_PLUGIN,
> then? I can live with the manual call, I'm just wondering if that's the way.
No. You can store a pointer to the type registration function somewhere
in order to prevent the linker from dropping the dependency.
I recommend the "custom directory layouts" section of
https://www.qt.io/blog/qml-modules-in-qt-6.2
best regards,
Ulf
More information about the Interest
mailing list