5
中再次显示和修改QList,以及我有一个问题(也许是一个问题),我使用qt和qml在qt5和qml中使用qtquick 2.0创建程序,并且我有一个C++模型qlist,我需要修改运行列表中,我使用q QQmlListProperty并显示在QML的项目,但它们不是隐藏和显示在那一刻,我添加或删除我的代码是未来:使用QQmlListProperty在Qml
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;
}
我使用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
}
为注释这仅适用于当暴露列表中改变了一切每次(例如为此列表中的HTTP一切都改变get请求),或者是更多钞票重新加载所有列表,而不会对程序流程造成影响。 – APRocha
append_concept(QQmlListProperty * list,Concept * cpt)应该抛出一个错误,不应该是QQmlListProperty类型? –