Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

C++ plugin for QML

$
0
0
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: #include <QtPlugin> #include <QDeclarativeExtensionPlugin> #include "version.h" #include "headers.h"   class Plugin: public QDeclarativeExtensionPlugin {     Q_OBJECT public:     void registerTypes(const char *uri)     { #include "regtypes.inc"     } };   Q_EXPORT_PLUGIN2(engine, Plugin) 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()?

Viewing all articles
Browse latest Browse all 4972

Trending Articles