将程序切分成三个文件QML(模型/视图/控制器)
我想将程序分成 3 个 QML 文件:一个包含数据模型 (XMLlistModel
) 的 QML 文件,另一个包含视图 (ListView
),第三个包含视图 (ListView
)。启动该程序。
import QtQuick 1.0
Item {
width: 800
height: 480
XmlListModel {
id: forecastModel
source: "http://www.google.com/ig/api?weather=&hl=fr"
query: "/xml_api_reply/weather/forecast_information"
XmlRole { name: "city"; query: "city/@data/string()" }
}
ListView {
x: 145; y: 325; width: 594; height: 48;
model: forecastModel
delegate: Text {
font.family: "Univers LT Std"; color: "#c8c8c8"; width: parent.width; font.pixelSize: 30
text: city
anchors.centerIn: parent.centerIn
}
}
}
I want to separate my program into 3 QML files: One QML file that contains the data model (XMLlistModel
), another that includes the views (ListView
), and the third to launch the program.
import QtQuick 1.0
Item {
width: 800
height: 480
XmlListModel {
id: forecastModel
source: "http://www.google.com/ig/api?weather=&hl=fr"
query: "/xml_api_reply/weather/forecast_information"
XmlRole { name: "city"; query: "city/@data/string()" }
}
ListView {
x: 145; y: 325; width: 594; height: 48;
model: forecastModel
delegate: Text {
font.family: "Univers LT Std"; color: "#c8c8c8"; width: parent.width; font.pixelSize: 30
text: city
anchors.centerIn: parent.centerIn
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将类似于
ForecastModel.qml
ForecastView.qml
main.qml
That would be something like
ForecastModel.qml
ForecastView.qml
main.qml