私は、C++ 部分がバックエンドと QML ユーザー インターフェイスの間の接続を結び付ける QML C++ プロジェクトを持っています。
QAbstractListModel プロパティを持つ QObject のサブクラスをコンテキスト プロパティとして設定します。
コンポーネントの 1 つに、qml ファイルで定義済みのリスト モデルがあります。そして、それを自分のリストモデルに置き換えたいと思います。しかし、コンテキスト プロパティが設定されていない場合は、そのモデルを保持したいと考えています。これにより、C++ 部分なしでプログラムを実行できます。モデルをコンテキスト プロパティとして設定しても、ローカル モデルがコンテキスト プロパティを無視したため、うまくいきませんでした。
私のQMLはそのように見えます
Rectangle {
id: root_rect
objectName: "root_rect"
width: 300
height: 300
color: "#dbdbdb"
ListModel {
id: myModel
ListElement {
name: "foo1"
fin: "bar1"
}
ListElement {
name: "foo2"
fin: "bar2"
}
}
Rectangle {
id: list_bg
color: "#ffffff"
clip: true
anchors.top: parent.top
anchors.topMargin: 10
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
anchors.left: parent.left
anchors.leftMargin: 10
anchors.right: parent.right
anchors.rightMargin: 10
ListView {
id: list_view1
anchors.fill: parent
delegate: Item {
x: 5
height: 40
Row {
id: row1
spacing: 10
Text {
text: name+" "+fin
anchors.verticalCenter: parent.verticalCenter
font.bold: true
}
}
}
model: myModel
//model: myObject.myModel
}
}
}
Designerでのデフォルト値の表示とGuiテスト用のqmlファイルのモデルと、そのmyObjectをコンテキストプロパティとして設定した場合の簡単な上書きの両方を持つことは可能ですか?
編集:QtQuick 1.1でQT 4を使用しています