[SOLVED] How to get to work c++ qml extension.
-
Hello!
The issue goes during porting my plugin to 4.8.h to 5.0.2. Utility qmlplugindump.exe gives me errors, but not correct types file. So i`l try to create empty plugin from QtCreator templates.
So, here is the generated code
@
#ifndef MYITEM_H
#define MYITEM_H
#include <QQuickItem>class MyItem : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(MyItem)
public:
MyItem(QQuickItem *parent = 0);
~MyItem();
};
QML_DECLARE_TYPE(MyItem)#endif // MYITEM_H
@@
#include "myitem.h"MyItem::MyItem(QQuickItem *parent): QQuickItem(parent){}
MyItem::~MyItem() {}
@@
#ifndef SAMPLEX_PLUGIN_H
#define SAMPLEX_PLUGIN_H#include <QQmlExtensionPlugin>
class SampleXPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")public:
void registerTypes(const char *uri);
};#endif // SAMPLEX_PLUGIN_H
@@
#include "samplex_plugin.h"
#include "myitem.h"#include <qqml.h>
void SampleXPlugin::registerTypes(const char *uri)
{
// @uri com.mycompany.qmlcomponents
qmlRegisterType<MyItem>(uri, 1, 0, "MyItem");
}
@and qmldir
@
module com.mycompany.qmlcomponents
plugin SampleX
@and pro file
@
TEMPLATE = lib
TARGET = SampleX
QT += qml quick
CONFIG += qt pluginTARGET = $$qtLibraryTarget($$TARGET)
uri = com.mycompany.qmlcomponentsInput
SOURCES +=
samplex_plugin.cpp
myitem.cppHEADERS +=
samplex_plugin.h
myitem.hOTHER_FILES = qmldir
@After compiling i`l try to execute qmlplugindump (in the folder there qmldir and dll):
qmlplugindump com.mycompany.qmlcomponents 1.0
@
QQmlComponent: Component is not ready
"file:///typelist.qml:2:1: module "com.mycompany.qmlcomponents" is not installed"
@qmlplugindump com.mycompany.qmlcomponents 1.0 ./SampleX.dll
@
QQmlComponent: Component is not ready
file:///D:/tmp/c/qt/untitled3/qmldir: plugin cannot be loaded for module "": Module namespace 'com.mycompany.qmlcompone
nts' does not match import URI ''"
@If i`l using qmldir
@
plugin SampleX
@and qmlplugindump -path ./
@
Module '' does not contain a module identifier directive - it cannot be protected from external registrations.
@Why?
p.s. compiling with vs2010.
-
So, the qmlplugindump has work if you execute them in this way
@
File structure
.../folder/PluginNameAnd command line is
qmlplugindump PluginName 1.0 .../folder/
It
s work if your working dirrectory is .../folder/. In all other cases it
s fail.
@After debuging qmlplugindump sources i think that the QQmlEngine::setImportPath or QQmlEngine::addImportPath QQmlEngine don`t work as expected.
And yes, -path options don
t work for c++ plugins any more. I
l try and possible combinations of path
d and options. The qmlplugindump use import "." for module loading in that case and it`s not work anymore. -
Any luck with this @misterion ?? Working ferociously on adding my own plugin to a project but have yet to come to a solution..