Используйте QQmlListProperty, чтобы показать и изменить QList в Qml
опять же, у меня есть вопрос (и, возможно, проблема), я делаю программу с qt и qml в qt5 и qml с qtquick 2.0, и у меня есть qlist модели c ++, и мне нужно изменить список во время выполнения, я использую q QQmlListProperty и показать элементы в qml, но они не скрываются и отображаются в тот момент, когда я добавляю или удаляю свой код, следующий:
class ConceptsList: public QObject{
Q_OBJECT
Q_PROPERTY(QQmlListProperty concepts READ concepts NOTIFY conceptsChanged)
Q_CLASSINFO("DefaultProperty", "concepts")
public:
ConceptsList(QObject *parent=0);
QQmlListProperty concepts();
Q_INVOKABLE static void append_concept(QQmlListProperty *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 *property);
static int conceptsSize(QQmlListProperty *property);
static Concept *conceptAt(QQmlListProperty *property, int index);
signals:
void conceptsChanged();
private:
QList m_concepts;
}
Я использую listview и делегат, и у меня нет проблем для просмотра, но мой вопрос заключается в том, могу ли я использовать QQmlListProperty и изменить Qlist, или я изменю форму, чтобы представить qlist в qml, если он 'Возможно, как вызвать метод из qml, или как реализовать в C ++, я спрашиваю, потому что существует очень мало числа или примеров работы с этой формой. в qml мой код следующий:
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
}