Use QQmlListProperty para mostrar y modificar QList en Qml
otra vez, bueno, tengo una pregunta (y quizás un problema), hago un programa con qt y qml en qt5 y qml con qtquick 2.0, y tengo un qlist modelo de C ++, y necesito modificar la lista en tiempo de ejecución, uso q QQmlListProperty y muestra los elementos en qml, pero no se ocultan ni se muestran en el momento en que agrego o elimino mi código:
class ConceptsList: public QObject{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<Concept> concepts READ concepts NOTIFY conceptsChanged)
Q_CLASSINFO("DefaultProperty", "concepts")
public:
ConceptsList(QObject *parent=0);
QQmlListProperty<Concept> concepts();
Q_INVOKABLE static void append_concept(QQmlListProperty<Concept> *list, Concept *cpt);
Q_INVOKABLE void removeConcept(int index);
Q_INVOKABLE void addConcept(QString m_id,QString description, QString quantity, QString price, QString unit, QString total);
Q_INVOKABLE int countConcepts();
static void clearConcepts(QQmlListProperty<Concept> *property);
static int conceptsSize(QQmlListProperty<Concept> *property);
static Concept *conceptAt(QQmlListProperty<Concept> *property, int index);
signals:
void conceptsChanged();
private:
QList<Concept *> m_concepts;
}
Utilizo una vista de lista y delegado y no tengo problemas para ver, pero mi pregunta es si puedo usar una QQmlListProperty y modificar la Qlist, o cambiaré un formulario para exponer qlist a qml, si es posible cómo llamar al método desde qml , o cómo implementarlo en C ++, pregunto porque existe muy poco número o ejemplos con este formulario. en qml mi código es el siguiente:
ConceptsList{
id:cpts
concepts:[
Concept{
m_id:"7"
m_quantity: "3"
m_price: "1"
m_unit:"1"
m_description:"algo"
m_total:"2"
}
]
}
ListView {
id: listConceptsView
objectName: "list"
anchors.fill: parent
anchors.margins: 5
clip: true
focus: true
highlight: highlightBar
highlightFollowsCurrentItem: false
Component{
id: tableConceptDelegate
Item{
anchors.margins: 4
width: 515
height: 27
clip: true
Row {
spacing: 4
Text {
height: 26; width: 76
text: model.m_id
color: "black"
font.bold: true
horizontalAlignment: Text.AlignHCenter
}
...
...
Text {
height: 26; width: 120
text: model.m_total//amountTotal
color: "black"
font.bold: true
horizontalAlignment: Text.AlignHCenter
}
}
MouseArea {
id: mouse_area1
anchors.fill: parent
onClicked:
{
listConceptsView.currentIndex = index
}
}
}
}
delegate: tableConceptDelegate
model:cptCpt // i define this alias how cptCpt: cpt.concepts
}