Well, thank you for your reply. I solved the problem with another solution though, and now I'm to far ahead that it would be a pain to test your solution. I used the function createQmlObject which uses a string as the "builder", and, somehow, the binding is never lost.
But I have a new problem, regarding some data view model guided software.
I want to manipulate an array of "zoneMappers"
Notice the following code:
function buildZone(buildString) {
var zone;
zone = Qt.createQmlObject(buildString, layout);
zoneMappers.push(currZoneMapper);
}
function buildZone(buildString) {
var zone;
zone = Qt.createQmlObject(buildString, layout);
zoneMappers.push(currZoneMapper);
}
To copy to clipboard, switch view to plain text mode
The "buildString" contains a QML file as a string with a ever incrementing number (increases in main.cpp every time you call buildZone) in one of the properties that binds the C++ object to a property in qml with setContextProperty (the only way I know to share an object with qml).
The QMLObject "zone" is not even used anymore, because I want to create a unique access point to both QML and C++ in order to change the visual components.
In main I have the following code:
//zoneMapperList as a QList with several ZoneMapper instances
for(int i = 0; i< zoneMapperList.count(); i++){
engine.rootContext()->setContextProperty(zoneMapperId, zoneMapperList[i]);
engine.rootContext()->setContextProperty("currZoneMapper", zoneMapperList[i]);
zoneMapperList[i]->setViewId(zoneMapperId);
if(!QMetaObject::invokeMethod(layoutObject,
"buildZone", Q_ARG
(QVariant, zoneMapperList
[i
]->getZoneBuilderString
()) )){ zoneMapperList[i]->setViewId("");
}
else{
zoneMapperList[i]->setViewObject(layoutObject->findChild<QObject*>(zoneMapperList[i]->getViewId()));
}
}
//zoneMapperList as a QList with several ZoneMapper instances
for(int i = 0; i< zoneMapperList.count(); i++){
QString zoneMapperId(QString("zoneMapper%1").arg(i));
engine.rootContext()->setContextProperty(zoneMapperId, zoneMapperList[i]);
engine.rootContext()->setContextProperty("currZoneMapper", zoneMapperList[i]);
zoneMapperList[i]->setViewId(zoneMapperId);
if(!QMetaObject::invokeMethod(layoutObject, "buildZone", Q_ARG(QVariant, zoneMapperList[i]->getZoneBuilderString()) )){
zoneMapperList[i]->setViewId("");
}
else{
zoneMapperList[i]->setViewObject(layoutObject->findChild<QObject*>(zoneMapperList[i]->getViewId()));
}
}
To copy to clipboard, switch view to plain text mode
You can see the "not so fancy" solution I used: "currZoneMapper". I use this "currZoneMapper" because I have no other way of adding a new C+ object and add it to the array.
The first string "zoneMapperID", which is something like "zoneMapper4" is used so QML gets different objects as different properties (with setContextProperty) and stores it in an array, so it can manipulate them as C+ objects.
Is there a better way to bind dynamic objects to dynamic qmlcomponents and manipulate them as one entity only?
Thank you!
Bookmarks