Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Extension Plugin as static library



  • Hi,

    I'm trying to organize my code a little bit, but I'm failing put my shared qml files and C++ components in a separate library. I also want to "protect" my qml files by putting them in a resource file (I'm working on windows + Visual Studio + Qt VS addin). My structure is as follows

    RootFolder
    -Binaries
    --MyApp,exe
    --SharedQMLLibrary.lib
    -Source
    --MyApp
    ---Main.cpp
    ---MyAppMainWindow.qml
    --Libraries
    ---SharedQMLLibrary
    ----SharedWindow.qml
    ----SharedComponent.cpp
    ----qmldir
    ----SharedQMLLibraryResource.qrc

    In MySharedQMLLibrary i have a resource.qrc file which has qmldir and SharedWindow.qml as a file. In MyApp i have in the Main.cpp file Q_INIT_RESOURCE(SharedQMLLibraryResource); The qmldir file just contains :
    SharedWindow 1.0 SharedWindow.qml
    In my MyAppMainWindow.qml i can just do

    #import 'qrc:/.'
    
    SharedWindow
    {
    }
    ...
    

    and it works. Now I'm struggling to make the C++ components available in MyMainWindow.qml.
    I've created a SharedQMLLibrary_plugin class which inherits from QQmlExtensionPlugin and in the registerTypes method i've added

    qmlRegisterType<SharedComponent>(uri, 1, 0, "SharedComponent");
    

    I've also updated the qmldir file to

    module MyModule
    SharedWindow 1.0 SharedWindow.qml
    plugin sharedqmllibrary
    

    but when i try to do in the MyAppMainWindow.qml

    #import 'qrc:/.'
    #import MyModule 1.0
    
    SharedComponent
    {
    }
    ...
    

    It complains that module "MyModule" plugin "SharedQMLLibrary" not found. Anybody has any advice on how the qmldir file should look like, what i should import in the application qml files and how the output libraries in my binaries folder should be structured?
    Thanks,

    Jan



  • Hmm, I think my brain doesn't work well today. The qmldir stuff is only necessary for a shared library. Just a static library is ok... I can easily make my own init function in it to register all the types and i don't need the qmldir stuff (made it work with a dll to, i just forgot to put the dll on the correct location). Nevermind, problem solved, sorry for the confusion...


Log in to reply