Accessing Qml from C++ plugin.
-
Basicly what I want is a pointer to QQmlApplicationEngine engine that can be accessed from a c++ plugin that I wrote. So any ideas?
P.S. I have tried almost everything I could, so I would need a full step-by-step explanation on what shold I do, otherwise I might make the same mistakes I'm currently dealing with. -
Try this.
class ShapeInterface
{
public:
ShapeInterface(){}
virtual void myname() = 0;
virtual void drawme() = 0;
virtual void setEng(QQmlEngine *eng)=0;
};Implement this plugin using the Plugin mechanism.
QQmlEngine *eng = viewer.engine(); QPluginLoader bosch("PthinksPlugin.dll"); QObject *obj = bosch.instance(); if (obj ) { qDebug() << "instance creation succes" <<endl; ShapeInterface *iface = qobject_cast<ShapeInterface*>(obj); iface->myname(); eng->setObjectName("Plugin"); iface->setEng(eng);
}
If you need complete sample I can dump it.
-
[quote author="Dheerendra" date="1406824938"]Try this.
class ShapeInterface
{
public:
ShapeInterface(){}
virtual void myname() = 0;
virtual void drawme() = 0;
virtual void setEng(QQmlEngine *eng)=0;
};Implement this plugin using the Plugin mechanism.
QQmlEngine *eng = viewer.engine(); QPluginLoader bosch("PthinksPlugin.dll"); QObject *obj = bosch.instance(); if (obj ) { qDebug() << "instance creation succes" <<endl; ShapeInterface *iface = qobject_cast<ShapeInterface*>(obj); iface->myname(); eng->setObjectName("Plugin"); iface->setEng(eng);
}
If you need complete sample I can dump it.[/quote]
Wow, newer thought it would get this complicated. :)
Actualy this is an sub-question of one: "I've already asked":http://qt-project.org/forums/viewthread/45545/ . Here you can find the code.
The only progress I've made is that stack overflow guys figured out this line: @QCoreApplication::postEvent(engine->rootObjects().first, event);@
Everything looks ok, but the problem is in accessing engine. I've tried everything I know about pointers in Qt. As For your suggestion, Dheerendra, I would gladly check it if you would show me how it works in example of my plugin, which I gave link to above. Thanks in advance.