View Full Version : How to append one more item to VisualItemModel?

15th November 2010, 05:50
I have defined a list view which has to show some Clocks that have their onw shape. So, I need not define any delegate to the list view. Hence, I have used VisualItemModel for the list view.
Now, I want to append one more item to the model in some other qml file.
How can I do that? I have tried below things but getting syntax errors.

I have defined the list view and model in this way:
************************************************** *
// Create the world clock view
VisualItemModel {
id: clocksModel
Clock { city: "New York, USA"; shift: -4; anchors.horizontalCenter: window.horizontalCenter }
Clock { city: "Mumbai, INDIA"; shift: 5.5; anchors.horizontalCenter: window.horizontalCenter }
Clock { city: "Tokyo, JAPAN"; shift: 9; anchors.horizontalCenter: window.horizontalCenter }
Clock { city: "Karachi, PAKISTAN"; shift: 6.5; anchors.horizontalCenter: window.horizontalCenter }
Clock { city: "Sydney, AUSTRALIA"; shift: 18; anchors.horizontalCenter: window.horizontalCenter }
Clock { city: "Boston, USA"; shift: -3.5; anchors.horizontalCenter: window.horizontalCenter }

ListView {
id: worldClock
anchors.top: titleBar.bottom
anchors.left: window.left
anchors.right: window.right
anchors.bottom: toolbar.top
clip: true
height: parent.height
visible: true
model : clocksModel
transform: Rotation {
id: worldClockViewRotation; origin.x: parent.width; origin.y: parent.height
axis.x: 0; axis.y: 1; axis.z: 0
************************************************** ****

Now, in another qml file, depending some use action, I want to append one more "Clock" item to the model in this way:
************************************************** ******
MouseArea {
anchors.fill: parent
onClicked: {
var city = cityTextEdit.text + "," + countryTextEdit.text;

clocksModel.append(Clock {
city: city; shift: gmtTextEdit.text;
anchors.horizontalCenter: window.horizontalCenter
// Get the details entered by user
// Switch to main view
window.state = "worldClockState"
addCityEditor.state = "Hide"
************************************************** *******

Its showing syntax error "Expected: )" at the brace '{' that is followed after 'Clock'.

Please let me kniw how can I acheive my use case here.


3rd December 2010, 12:11
Did you find a solution to this problem? I am trying to do a similar thing.



15th December 2011, 15:07
Hi guys,

I would also be interested in this.
Did you find any solution?