Hi, The relevant bug is https://bugreports.qt-project.org/browse/QTBUG-24456.
For now, using dynamicRoles as Joona suggested should work around the problem. Cheers -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Petrell Joona.T (Nokia-MP/Tampere) Sent: Tuesday, June 26, 2012 7:46 AM To: [email protected]; [email protected] Subject: Re: [Development] Behavior change in QtQuick 2.0 Qml ListModel (for javascript date object) Hi Nils, > Bug or feature? Sounds like a bug, though your code will work in Qt Quick 2.0 if you enable dynamic roles in your ListModel, that is write ListModel { dynamicRoles: true }. Due to performance reasons ListModel in Qt Quick 2.0 has changed to use static roles by default instead of dynamic roles (see http://doc-snapshot.qt-project.org/5.0/qml-qtquick2-listmodel.html#dynamicRoles-prop). The new code path seems to break the Date object. It may also be that there is a reason why ListModel does not support the Date object, but if so it is not immediatelly obvious from the documentation what native JavaScript types can be stored in ListModel and what not. Cheers, Joona ________________________________________ From: [email protected] [[email protected]] on behalf of ext Nils Jeisecke [[email protected]] Sent: Monday, June 25, 2012 4:15 PM To: [email protected] Subject: [Development] Behavior change in QtQuick 2.0 Qml ListModel (for javascript date object) 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 _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
