[Interest] Best model type for shared data between C++ and QML, as well as insertion and removal on both sides.
Nuno Santos
nunosantos at imaginando.pt
Thu Nov 20 15:38:44 CET 2014
Hi,
I need to implement a model class that allows me to have the data in C++ but exposed to QML.
The data will need to be exposed to QML and it will be necessary to write from QML to that model as well.
The C++ side will be in charge of the data persistence.
I started with QQmlListProperty and it works for having data exposed from C++ to QML. The problem is that I also need to dynamically instantiate data on the QML side and write to the list. That doesn’t seem to be possible, or, if it is, I don’t know how to get there. So far I have only been able to write to the list, writing the items on the property it self. See example below.
What I am trying to do with QQmlListProperty is possible or should I adopt another model type such as QAbstractListModel?
Thanks
Nuno
Example:
// works
PatchSetManager {
id: patchManager
presets: [
PatchSet {
name: "Preset 1"
patches: [
Patch {
name: "Patch 1"
},
Patch {
name: "Patch 2"
}
]
}
]
}
// doesn’t work
var patchSet = Qt.createQmlObject('import Imaginando 1.0; PatchSet {}', patchManager);
if (patchSet)
{
console.log("object created successfully");
}
patchSet.name = "test"
var patch = Qt.createQmlObject('import Imaginando 1.0; Patch {}', patchSet);
if (patch)
{
patchSet.patches.append(patch)
console.log(patchSet.patches + " length: " + patchSet.patches.length)
}
More information about the Interest
mailing list