Load QML Plugins through QDeclarativeEngine
-
Hi there!
I currently try to get the QWidgets (in the CppExtensions-Examples) running.
Having the standard example code and trying to load the qml through QDeclarativeEngine gives me the error, that MyPushButton is not a type.
What am I missing?
As those plugins are intended to dynamically extend QML, I'm pretty sure, that I don't have to register the type in my core-application (just providing a kind of self-written qmlviewer). Later on the core-application should do some system related stuff aswell, so using the qmlviewer itself won't help :(
Thanks in advance!
Ali -
MyPushButton is just a simple QPushButton wich should be provided to qml with a plugin
It is implemented in the examples (declarative/cppextensions/qwidgets)Here you go: "Link":http://doc.troll.no/master-snapshot/declarative-cppextensions-qwidgets.html
For this discussion I have chosen a provided example on purpose - so we have the same discussion base ;)
-
Having
@import "QWidgets" 1.0@
in my test qml File (qwidgets.qml)I don't intend to register the MyPushButton Type in my cpp core-application. The qmlRegisterType should be done through the QWidgetsPlugin (derived from QDeclarativeExtensionPlugin).
I use the example as it is - absolutely no modification. (qwidgets.pro/.qml/.cpp and qmldir used from example)
The point is, that I can't use the qmlviewer to load it, but have to use my own application using a QDeclarativeEngine
The Code is kinda straight forward:
@#include <QtDeclarative>
#include <QCoreApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QDeclarativeComponent>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv); QDeclarativeEngine engine; QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext()); QDeclarativeComponent component(&engine, "qwidgets.qml"); QObject *window = component.create(context); qDebug() << component.errors(); return app.exec();
}@
As I understand QML plugins are supposed to work that way... else ... well, that would be pretty sad ;)