Use QQmlListProperty to show and modify QList in Qml

后端 未结 1 900
离开以前
离开以前 2021-01-13 01:36

again, well i have a question (and maybe a problem), i make a program with qt and qml in qt5 and qml with qtquick 2.0, and i have a c++ model qlist, and i need modify the li

1条回答
  •  没有蜡笔的小新
    2021-01-13 01:59

    I got the answer for my self, first, I stopped using the attribute Q_INVOCABLE in the method append_concept, second, I added a line of code in the implementation of addConcept. Here is the code:

    Before:

    Q_INVOKABLE static void append_concept(QQmlListProperty *list, Concept *cpt);
    

    Now:

    static void append_concept(QQmlListProperty *list, Concept *cpt);
    

    Maybe this not affect, but i prefer not take risks.

    And in the implementations of addConcept and removeConcept:

     void ConceptsList::addConcept(QString m_id, QString quantity, QString price, QString unit, QString description)
     {
       Concept *cpt=new Concept(m_id, quantity, unit, price, description);
    
       m_concepts.append(cpt); 
       this->conceptsChanged();
     }
    
    void ConceptsList::removeConcept(int index)
    {
      m_concepts.removeAt(index);
      this->conceptsChanged();
    }
    

    0 讨论(0)
提交回复
热议问题