Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. setHours() do not work
Forum Updated to NodeBB v4.3 + New Features

setHours() do not work

Scheduled Pinned Locked Moved Solved QML and Qt Quick
javascriptdateqml
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alart
    wrote on last edited by Alart
    #1

    Hello, that's my very first post here.
    Let me skip to the point. In my qml file setHours() function, (part of date prototype) does not work. However, getters do work. Here is my code:

    var new_time = (calendarForDate.chosen_Hour.getMinutes() + 1)%60
    console.log(new_time) // new_time is calculated properly
    calendarForDate.chosen_Hour.setMinutes(new_time)
    console.log(calendarForDate.chosen_Hour.getMinutes()) // now it's the same as before anyway
    

    My question - I don't know...
    Is there something wrong with that?
    Is that a bug?
    I'm using qtcreator under KDE Mint but it's installation directly from qt, not Ubuntu SDK. I'm more c++ man, so I'm not sure.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Can you create a complete minimal working example qml file?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alart
        wrote on last edited by Alart
        #3

        Luckily I found solution myself :)
        According to http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html#javascript-environment-restrictions "global" object cannot be modified inside a JavaScript function.
        In this cause that code was part of onClicked property.
        Proper code:

        onClicked : {
              var working_time = calendarForDate.chosen_Hour; // local variable
              working_time.setHours( (calendarForDate.chosen_Hour.getHours() + 1)%24 ); // now JavaScript can modify that
              calendarForDate.chosen_Hour = working_time;
              console.log(calendarForDate.chosen_Hour.getHours()); // one cannot modify global object, but that's perfectly fine
              hoursField.text = calendarForDate.chosen_Hour.getHours() // now it works as intended
        }
        

        Thanks for you attention.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved