[Interest] What is the right way of creating a static lib that has qml resources with cmake?

Nuno Santos nuno.santos at imaginando.pt
Thu Jan 12 10:13:54 CET 2023


Ulf,

I based myself on the example provided in the documention -> https://doc.qt.io/qt-6/qtqml-writing-a-module.html

In the cmake build directory there was no dylib present, only static libs, so the same issue is not happening in this smaller case. 

However, when declaring import ExtraModule on main.qml, it's not found and the plugin is being registered on main.cpp via 

#include <QtQml/qqmlextensionplugin.h>
Q_IMPORT_QML_PLUGIN(ExtraModulePlugin)

What am I missing here? Project attached.

Regards,

Nuno



> On 12 Jan 2023, at 08:45, Nuno Santos <nuno.santos at imaginando.pt> wrote:
> 
> Ulf,
> 
>> On 12 Jan 2023, at 08:36, Ulf Hermann <ulf.hermann at qt.io> wrote:
>> 
>> If you state STATIC in qt_add_qml_module (without a qt_add_library or similar that makes it dynamic) and then it builds a dynamic library, that's a bug. Please file a report at https://bugreports.qt-project.org with a minimal reproducer and state the version of Qt you are using.
> 
> I have been using the following documentation as a guide:
> 
> https://doc.qt.io/qt-6/qtqml-writing-a-module.html
> 
> I will try to reproduce the problem basing myself on this. In case I need to submit a bug report what is the category?
> 
>> 
>> If it does build a static library but the library doesn't contain qInitResources, that's on purpose. You need to do the plugin linking dance which uses additional .o files ("object library" in CMake lingo) to pull in the resource initialization. That's because linkers "optimize" the resources out if you don't. We can't do much about this.
>> 
>> See also https://doc.qt.io/qt-6/qt-import-qml-plugins.html and https://doc.qt.io/qt-6/qqmlengineextensionplugin.html#Q_IMPORT_QML_PLUGIN
> 
> I have also seen this in the previous link and even that I have successfully made it link with the Q_IMPORT_QML_PLUGIN declaration, no resources were available. 
> 
> More on this later. I will start from the scratch with an example.
> 
> Thank you!
> 
> Best,
> 
> Nuno
> 
>> 
>> best regards,
>> Ulf
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230112/11383219/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myProject.zip
Type: application/zip
Size: 3557 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230112/11383219/attachment.zip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230112/11383219/attachment-0001.htm>


More information about the Interest mailing list