[Qt-qml] C++ Data Models and plugin mechanism

michael.brasser at nokia.com michael.brasser at nokia.com
Tue May 18 00:37:47 CEST 2010


On 18/05/2010, at 6:41 AM, ext Bartosh Wroblevksy wrote:
> I am enjoying QML. I wanted to confirm what I have been researching. Right now as it stands, if you want to extend a QML Data Model in C++ (as in the C++ Data Models section in http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html#C++). You can't do that with a plugin (similar to the plugin example). 
> 
> And this because somewhere the plugin would need to know about the QDeclarativeView to call
> 
> void QDeclarativeContext::setContextProperty ( const QString & name, QObject * value )
> 
> So you can only extend QML Data Model by reimplementing QDeclarativeView. Am I correct?

In a plugin, you can do the same thing from the initializeEngine function:

QDeclarativeContext *ctxt = engine->rootContext();
ctxt->setContextProperty("myModel", model);

(see the declarative imageprovider example for a working example)

Regards,
Michael





More information about the Qt-qml mailing list