Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

How to set property into a sub context?

$
0
0
Hello, I try to pass an object (ListModel) into a sub-context of an component that I have created, but I have this error: QQmlContext: Cannot set property on internal context Here, my attempts: QQmlComponent component(engine, QUrl::fromLocalFile("myScene.qml")); QObject *object = component.beginCreate( engine->rootContext() ); qobject_cast<QQuickItem*>(object)->setParentItem(window2);  //assign my scene to a qml window. window2 is a QQuickItem   QQmlContext *context0 = engine->rootContext(); //works but conflict QQmlContext *context1 = engine->contextForObject( window2 ); //doesn't work QQmlContext *context2 = engine->contextForObject( object ); //doesn't work QObject *object2 = object->findChild<QQuickItem*>("Rect"); //Rect is the first child in myScene QQmlContext *context3 = engine->contextForObject( object2 ); //doesn't work QObject *object3 = object->findChild<QQuickItem*>("myRepeter"); //myRepeter is the final child which uses my property QQmlContext *context4 = engine->contextForObject( object3 ); //doesn't work   context2->setContextProperty("myList", myModelList); component.completeCreate(); Why is it not possible to set a property elsewhere than the rootcontext? I can’t use the rootcontext because I will create several scenes with several differents models. With the root context, there is a name conflit. I also tried to use: object3->setProperty("myList", myModelList); but i have a lot of compilation errors. Probably, I will try to use a table of models and set an index into my “myScene” to solve my problem. But I want to know why is it not possible to set a object to the context of an child item, or how to avoid conflicts of names in this situation? Thanks.

Viewing all articles
Browse latest Browse all 4972

Trending Articles