PDA

View Full Version : QML Extension plugin as static library



JanW
13th July 2016, 14:49
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

anda_skoa
13th July 2016, 15:28
Can you clarify if the title or the content of your posting reflects your goal better?
Do you want a static library or a plugin?

Cheers,
_

JanW
13th July 2016, 15:46
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...