[Development] Behavior change in QtQuick 2.0 Qml ListModel (for javascript date object)
Nils Jeisecke
njeisecke at saltation.de
Mon Jun 25 15:15:40 CEST 2012
Hi,
the following code works just fine with Qt Quick 1.1.
However porting this to 2.0 gives the following output:
date is [object Object]
file:///...q2listmodel.qml:9: TypeError: Object #<Object> has no
method 'getMonth'
Does the new ListModel/ListElement implementation apply some automatic
conversion for javascript date objects?
Putting other javascript objects in there works just fine.
---
import QtQuick 1.1 /* 2.0 */
Item {
ListModel { id: listModel }
Component.onCompleted: {
listModel.append({ "date": new Date } )
console.log("date is " + listModel.get(0).date)
console.log("month is " + listModel.get(0).date.getMonth())
}
}
---
Interestingly wrapping the date object in another object works:
---
import QtQuick 2.0
Item {
ListModel { id: listModel }
Component.onCompleted: {
listModel.append({ date: { x: new Date } }) /* wrap into x */
console.log("date is " + listModel.get(0).date.x)
console.log("month is " + listModel.get(0).date.x.getMonth())
}
}
---
Bug or feature?
Nils
More information about the Development
mailing list