将程序切分成三个文件QML(模型/视图/控制器)

发布于 2024-11-17 08:05:34 字数 812 浏览 1 评论 0原文

我想将程序分成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇到 2024-11-24 08:05:34

这将类似于

ForecastModel.qml

XmlListModel {
    source: "http://www.google.com/ig/api?weather=&hl=fr"
    query: "/xml_api_reply/weather/forecast_information"
    XmlRole { name: "city"; query: "city/@data/string()" }
}

ForecastView.qml

ListView {
    x: 145; y: 325; width: 594; height: 48;
    delegate: Text {
        font.family: "Univers LT Std"; color: "#c8c8c8"; width: parent.width; font.pixelSize: 30
        text: city
        anchors.centerIn: parent.centerIn
    }
}

main.qml

import QtQuick 1.0

Item {    
    width: 800
    height: 480

    ForecastModel {
        id: forecastModel
    }

    ForecastView {
        model: forecastModel
    }
}

That would be something like

ForecastModel.qml

XmlListModel {
    source: "http://www.google.com/ig/api?weather=&hl=fr"
    query: "/xml_api_reply/weather/forecast_information"
    XmlRole { name: "city"; query: "city/@data/string()" }
}

ForecastView.qml

ListView {
    x: 145; y: 325; width: 594; height: 48;
    delegate: Text {
        font.family: "Univers LT Std"; color: "#c8c8c8"; width: parent.width; font.pixelSize: 30
        text: city
        anchors.centerIn: parent.centerIn
    }
}

main.qml

import QtQuick 1.0

Item {    
    width: 800
    height: 480

    ForecastModel {
        id: forecastModel
    }

    ForecastView {
        model: forecastModel
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文