[Interest] [Qt6] QML automatic type registration in a (shared) library

Konstantin Shegunov kshegunov at gmail.com
Fri Jan 14 16:40:04 CET 2022


On Fri, Jan 14, 2022 at 7:18 AM Ulf Hermann <ulf.hermann at qt.io> wrote:

> Well, no, that doesn't work. If your module is called Tsc.Ui, then it
> needs to live in a directory called Tsc/Ui/, not TscUi/. That's the
> reason why the explicit file system import path doesn't work either.
>

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.

I guess your linker ignored the linkage because you don't "use" any
> symbols from the linked library. You need to do the plugin linking trick
> with Q_IMPORT_QML_PLUGIN.
>

That doesn't work as it's not a static plugin. However this put me on the
right track (or at least I believe it is). Adding this to main():

extern void Q_DECL_IMPORT qml_register_types_Tsc_Ui();

qml_register_types_Tsc_Ui();

Did load the resources properly and I can see the QML module is loaded
(after also adding the import path to ":/")

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220114/1e2484b3/attachment.htm>


More information about the Interest mailing list