How to separate a program in Model/View/Controller
-
Do you mean you want to have model, view, and delegate coming from different QML files.. can you clarify? Your question is not clear. As I see it, they are already separated.
-
exactly, I want to separate it in 3 QML files
-
You can put XmlListModel in separate file (let's call it MyModel.qml) and use MyModel from your qml code (if it will be in another directory you should import this path). Please read Qt Assistant to get further information
-
That you can always do that.. have three qml files and have your list view, delegate, and model in those files. But you need to connect them all the above qml file. I mean creating concrete objects of those three items and assigning your model element to Model and same for delegate.
But I don't see a good reason to separate them? do you have any reason.
-
"This":http://doc.qt.nokia.com/4.7/qdeclarativemodules.html#qml-modules might help you
-
The purpose of separating them is to have a QML file that contains the data model (XMLlistModel), another that includes the views (TextInput, ListView), and the third to start the program
-
the problem is ListView can not find the id of XMLlistModel if I separated the two into two files
-
You should not use them by id, but create new objects from your qml files.
-
Read this "Managing Documents":http://doc.qt.nokia.com/4.7/qdeclarativedocuments.html
-
You don't give up :)
First read http://doc.qt.nokia.com/4.7/qdeclarativedocuments.htmlthen to solve your problem....
XmlModel.qml
@ import QtQuick 1.0
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()" }
}
@TextDeligate.qml
@ import QtQuick 1.0Component {
Text {
id : textItem
font.family: "Univers LT Std";
color: "#c8c8c8";
width: parent.width;
font.pixelSize: 30
text: city
anchors.centerIn: parent.centerIn
}
}
@ListItem.qml
@ import QtQuick 1.0
ListView {
x: 145; y: 325; width: 594; height: 48;
}
@now in your main.qml
@ import QtQuick 1.0
Item { XmlModel { id: modelItem } ListItem { id: listItem model: modelItem deligate: TextDeligate { } }
}@
There could be syntax errors, please correct them. Understand what I tried to do. Don't just copy :)
-
tank you Vijay Bhaska Reddy i try to do it