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

Konstantin Shegunov kshegunov at gmail.com
Wed Jan 19 09:30:43 CET 2022


On Wed, Jan 19, 2022 at 9:56 AM Alexandru Croitor <alexandru.croitor at qt.io>
wrote:

> As far as I know, the referenced merge request only implements an
> abstraction for decorations, but does not implement the specific decoration
> of making sure a library is not discarded.
>

Yes, that's my understanding of the discussion as well. LINK_WHAT_YOU_USE
is supposed to do the right thing, however it's documented for ELF only,
and even then I wasn't able to make it work. That's why I started with the
g++ -u someSymbol  and /INCLUDE:someSymbol instead.

There are WIP changes that try to do that.
> See https://codereview.qt-project.org/c/qt/qtdeclarative/+/367149


Oh, I just took the easy (perhaps wrong) approach. I pushed from the
backing target to the consumer a cpp file, which is a dummy containing the
pointer thing. It just contains (Tsc.Ui is my module's URI):

extern TSCUI_API void qml_register_types_Tsc_Ui();

inline volatile auto tscUiTypeRegistration = &qml_register_types_Tsc_Ui;

I haven't tested it with static libraries, as generally I do avoid them,
but does work for for the shared one (as expected).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220119/74d5ae7b/attachment.htm>


More information about the Interest mailing list