Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82598

Establish a public API for building static QML plugins

    XMLWordPrintable

Details

    Description

      There is detailed documentation about how to create shared QML plugins and it works fine, but there is no documentation about how to create them statically. And the plugins can't be loaded successfully if they are compiled statically.

      I've seen there are a few paragraphs teaching people how to create static plugins, but it's not about QML plugins. And why static QML plugins can't be loaded has nothing to do with Q_INIT_RESOURCE() or anything like that, the main problem is the plugin can't be registered and recognized by the QML engine.

      Actually there's more work to do if people want to build a static plugin, because I opened "qml_plugin.prf" and "qml_module.prf" and found something not mentioned anywhere in the documentation.

      I hope this issue can be fixed soon because it's a common use case and it's really a headache without any documentation to follow.

       

      I now figured out how to build QML plugins statically after digging into some .prf files and QML plugins:
      For the .pro file, we have to add one line:

      QMAKE_MOC_OPTIONS += -Muri=$$QML_IMPORT_NAME
      

      And all .qml files and the qmldir file (and all other assets if exist) have to be packed into the static library, under the "/qt-project.org/imports/balabalabala" prefix.
      For the source file, we have to add the following line:

      extern void qml_register_types_balabalabala();
      

      And we should use it in the constructor function:

      volatile auto registration = &qml_register_types_balabalabala;
      Q_UNUSED(registration)
      

      Then the plugin can now be built as a static library and it can be recognized and loaded by the QML engine successfully.
      These steps are not complicated and are easy to understand, but I really like it be documented officially.

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crscott Craig Scott
              wangwenx190 赵 宇航
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes