How to deploy custom plugins QML
-
GoodMorning,
I'm using a Raspberry pi3 with Qt version 5.11 installed through boot2qt.
I'm struggling to understand to deploy a custom made plugin. I supposed the plugin has to be deploy both in the target (Rapberry) and in my host PC. I've followed both
http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html and https://docs.huihoo.com/qt/5.x/qtqml-tutorials-extending-qml-example.html#chapter-6-writing-an-extension-plugin, but they are not clear enough for me.
Basically I don't know where and how deploy the generated plugin..Can you advise?
Thank you very much.
Below you can find my .pro file
QT += qml quick CONFIG += c++11 TEMPLATE = lib CONFIG += qt plugin DESTDIR = imports/PieChart TARGET = qmlPieChartPlugin CONFIG += install_ok # Do not cargo-cult this! # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ piechart.cpp \ pieslice.cpp \ chartsplugin.cpp RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. # target.path = /home/root # INSTALLS += target HEADERS += \ piechart.h \ pieslice.h \ chartsplugin.h
The structure of my project is:
-
You can look at my simple example at GIT
-
Hello @dheerendra ,
thank you for your example. Since I'm a newbie with plugins, I didn't understand some things, so I have a couple of questions:-
Have you got an example that use the plugin as well? In this case, is it necessary to add the plugin path in QML_IMPORT_PATH?
-
I saw that in the target, both the qmldir file and the library .so are installed. Is it mandatory to transfer the qmldir file?
Besides in DESTDIR only the library is transferred (not qmldir), is it ok? -
I don't understand this part, what is its purpose:
!equals(_PRO_FILE_PWD_, $$OUT_PWD) { copy_qmldir.target = $$OUT_PWD/qmldir copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" QMAKE_EXTRA_TARGETS += copy_qmldir PRE_TARGETDEPS += $$copy_qmldir.target }
Thank you very much.
Best Regards,
DAvide Bruenlli -
-
Did you download the example & built it ? It has usage example in the same directory.
-
Hello @dheerendra,
now I see it. The programs works as expected,
I'm a little surprised that if in UseQMLPlugin main.cpp file, I comment out the engine.addImportPath(..), the program works even without it.
Can you also give some details about previous questions? (except question number 1, which is satisfied)Thank you.
-
qmldir should be there.
It is copying qmldir