5

繰り返しになりますが、質問があります (おそらく問題もあります)。qt5 で qt と qml を使用してプログラムを作成し、qtquick 2.0 で qml を使用してプログラムを作成します。また、C++ モデルの qlist があり、実行時にリストを変更する必要があるため、q を使用します。 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;
}

私はリストビューとデリゲートを使用していますが、表示に問題はありませんが、QQmlListProperty を使用して Qlist を変更できるかどうか、または qml からメソッドを呼び出す方法が可能であれば、qlist を 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
        }
4

1 に答える 1