[SOLVED] Proper way of creating complex QDeclarativeItem class exposed to qml by QDeclarativeExtensionPlugin
-
wrote on 11 Jun 2012, 14:24 last edited by
Hello all,
I need some expertise.Let's assume that I have class A that inherits from QDeclarativeItem. I want this item to be composed from few QDeclarativeComponent's created in A constructor. I need pointer tor QDeclarativeEngine for this.
I've achieved this by:
@
QmlPlugin: public QDeclarativeExtensionPlugin {
...
public:
static QDeclarativeEngine * engine;
....
void initializeEngine ( QDeclarativeEngine * _engine, const char * uri ) {
engine = _engine;
QDeclarativeExtensionPlugin::initializeEngine(engine,uri);
}
....
};
@Now I can get QDeclarativeEngine * from inside contructor of A class (QmlPlugin::engine), but...
- If I have 2 QDeclarativeView's that load 2 qml files that import this plugin, will it create 2 QDeclarativeEngine's and only one will be stored in this static variable?
- Is there more proper way of doing this?
-
wrote on 12 Jun 2012, 22:32 last edited by
Hi,
From within the class A constructor, you should be able to call qmlEngine(this) to get the engine that constructed the item. (I'm not sure if this function is documented -- you could also use QDeclarativeEngine::contextForObject(this)->engine())
Regards,
Michael -
wrote on 13 Jun 2012, 07:49 last edited by
Hello,
I supposed that there is more convenient way for getting pointer to QDeclarativeEngine from inside the plugin. As far as I know qmlEngine function is not documented but QDeclarativeEngine::contextForObject I have skipped somehow.
Thank You for hints! -
wrote on 13 Jun 2012, 10:02 last edited by
qmlEngine and QDeclarativeEngine::contextForObject returns NULL in class A constructor.
I've done creating additional internal components in A::onCompleted - there i can get pointer to engine from qmlEngine function.
1/4