qtqmlqdate

How can QML native `date` type be updated?


QML provides a date type that appears to be freely convertible to and from both the C++ QDate class and the QML Date type. The Date type is an extension of the JS Date type.

Calling the set methods on a date property is apparently permissible, because no error (e.g. "method missing") is thrown:

// in a QML object declaration
property date myDate: new Date()
// in a slot somewhere in the object
date.setYear(2002)

However, the date data is not changed; printing the date before and after calling setYear (or any other set method) causes exact same date string to be printed twice.

The QML documentation doesn't seem to say much about date type in the link provided above.


Solution

  • It appears (and air-dex's answer seems to confirm) that the date type simply can't be directly modified in this way. This is bizarre, because there are no errors triggered by attempts to call the methods.

    So the solution is to simply declare date-objects that must be modified later as var rather than date.