Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Extension Plugin as static library
Qt 6.11 is out! See what's new in the release blog

QML Extension Plugin as static library

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JanWJ Offline
    JanWJ Offline
    JanW
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • JanWJ Offline
      JanWJ Offline
      JanW
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved