Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] C++ plugin for QML
Hi, everybody! I have an application that consists of a QML part and C++ part (a lot of classes that can be accessed from QML). The QML files are located in a qrc.
I want to detach the C++ part and make a shared (or static) library named 'engine' to use with other projects.
I have read some tutorials and detached the C++ files. Also I've added a file "plugin.cpp" with the following code:
class Plugin: public QDeclarativeExtensionPlugin
void registerTypes(const char *uri)
headers.h and regtypes.inc are autogenerated files that do the registration. The example line of regtypes.inc:
@qmlRegisterType<Printer>(uri, VERSION_MAJOR, VERSION_MINOR, "Printer");@
The library compiles OK, I get the file libengine.so.
Please help me with importing the plugin into the QML program! I've tried many different ways, but I didn't succeed.
Where should I put the shared library? Should I link my executable with the library? Should I write the qmldir file and where should I put it? Should I do addImportPath()?
I've succeeded in importing my plugin from qmlviewer. To do that I had to add header file plugin.h with the definition of class Plugin to let the MOC process the class. Without that step the qmlviewer was unable to load the shared library.
The directory structure is:
@import QtQuitck 1.1
import engine 0.1
The command to run qmlviewer is:
@qmlviewer -I . main.qml@
Now I'm going to try importing the plugin from my executable.
To do importing the plugin from my application I had to add import path to the main view:
@mv->engine()->addImportPath("."); // mv is an object of class derived from QDeclarativeView@