Results 1 to 4 of 4

Thread: QML Date set problem

  1. #1
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default QML Date set problem

    In this code:

    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.4
    3.  
    4. Item {
    5. id: root
    6. property date value: new Date(2000, 0, 1)
    7. Button {
    8. onClicked: {
    9. root.value.setFullYear(2001)
    10. console.log(root.value)
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    When push the button, why date doesn't change? On the log appears 2000, not 2001

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML Date set problem

    Qt Code:
    1. onClicked: {
    2. var d = root.value
    3. d.setFullYear(2001)
    4. root.value = d
    5. console.log(root.value)
    6. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

    P.S.: the other posting wasn't a real reply, it was just spam.
    Last edited by anda_skoa; 25th October 2015 at 15:05.

  3. #3
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QML Date set problem

    Thank you very much for your response.

    Could you explain why my code doesn't work? I would like to understand it.

    Best regards.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML Date set problem

    I don't know why exactly either.

    It seems that the JavaScript context treats the property object more like a local object then a property.
    Only writes to the property itself are actual modifications of the property.

    Same happens, for example, if the property is a JavaScript array. I.e. you need to write a modified array value to the property in order for the property to change.

    My guess is that the QML engine can't easily track if the object has changed (JavaScript objects don't have change notification for their contents), so it requires and actual assignment to the property to be sure it can properly (re-)evaluate all bindings on that property.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2014, 00:41
  2. QML Date problem?
    By sonulohani in forum Qt Quick
    Replies: 1
    Last Post: 7th June 2012, 11:46
  3. Qwt date and time problem
    By CassioTC in forum Qwt
    Replies: 0
    Last Post: 25th August 2011, 13:39
  4. date-time problem
    By aegis in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2007, 18:45
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.