Hi,

I’m working on an entity-component based application. Basically an entity is a list of components and a component is just an object which has some simple data (ints, strings, floats,…). I have a list which shows all the entities in my application and I have a custom qml component which i call the “component editor”. The component editor is used to edit the simple data from a component of a selected entity(i use two way binding for this). The component editor can scroll through all the components of the selected entity (basically, there is a forward/back button which shows the next/previous component of the selected entity). I hope the basic idea is clear.

In my framework, I have a factory object, that for each component (each component has a type) generates a qmlInterfaceObject. The qml interface object is a qobject, which has the component as a member, it knows the qml file location for the component editor (the component editor has a loader which loads the qml file of the current component qml interface) and it has a string which identifies the context property which is used in the qml file to communicate with this qml interface (class variable).

When I select an entity in my list, the factory generates a qmlinterfaceobject (a pointer) for the first component of the entity. I do:

Qt Code:
  1. ...->rootContext()->setContextProperty(qmlinterfaceobject ->getNameOfContextProperty(), qmlinterfaceobject);
To copy to clipboard, switch view to plain text mode 

Now when I select another entity, another qmlinterfaceobject is created. If it is generated for the same type of component as the current qmlInterfaceObject, I call setContextProperty with the same name, but another pointervalue. When this happens, i get some very strange results (basically the new component is updated with the values of the old ones which are still in the interface). Is it not allowed to setcontextproperty twice for a given name? Is it maybe in this case better to create a new context every time i switch entities? Or is there a better solution for this?
Cheers,

Matt