[Solved] Pure QML plugin as a single file (library)

  • Hello! Now I have another question about QML plugins. I have a lot of qml files which should be shared between several applications. We ship the applications to the customers, and we don't want them to see a lot of qml files. I used to put the files into the resources of the application, and it worked good. But now I want to detach the qml files to a plugin and make them available from different applications. I know there is a way to put the files into a directory and write a qmldir file to describe it, but it's not suitable because we don't want users to see the bare code.
    Is there a way to make a single file (a shared library or an archive) from the set of qml files and load it making the qml types available in the application?

  • Moderators

    You can simply load resources dynamically. Divide your QML into as many .qrc files, and load ones you need in your application (with QResource::registerResource()).

  • OK, I've found the solution.

    Create new project as a static/dynamic library.

    Add the qml files to the project.

    Create a resource description with a custom prefix ('controls' for example), add there the qml files.

    Compile the library

    Add library import into the main application project's settings.

    Add resource initialization into the beginning of int main() of the application: @Q_INIT_RESOURCE_EXTERN(controls)

    Q_INIT_RESOURCE(controls); @

    Import library qml items by specifying the relative path:
    import "../controls"@

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.