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. Odd behavior when passing value through WorkerScript

Odd behavior when passing value through WorkerScript

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 1.8k 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.
  • O Offline
    O Offline
    owenzhao
    wrote on last edited by
    #1

    Please see the code first.
    main.qml
    @import QtQuick 1.1

    Rectangle {
    property real t1 //: value
    Component.onCompleted: {
    t1 = new Date().getTime()
    }

    Loader {
        id: dialogLoader
    }
    
    WorkerScript {
        id: testWorkderScript
        source: "test.js"
    }
    
    width: 360
    height: 360
    Text { id: text
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            console.log("t1 is  " + t1)
            testWorkderScript.sendMessage({'t1': t1})
        }
    }
    function test(t1, t2, t3) {
        text.text = t1
        console.log("ti, t2, t3 is " + t1 + ", " + t2 + ", " + t3)
    }
    

    }@

    test.js**
    @.pragma library

    WorkerScript.onMessage = function(message) {
    console.log("message: t1 is " + message.t1)
    }@

    my result in qt creator:
    @[Qt Message] t1 is 1339228771545
    [Qt Message] message: t1 is 1339228815360
    [Qt Message] t1 is 1339228771545
    [Qt Message] message: t1 is 1339228815360
    [Qt Message] t1 is 1339228771545
    [Qt Message] message: t1 is 1339228815360
    [Qt Message] t1 is 1339228771545
    [Qt Message] message: t1 is 1339228815360
    [Qt Message] t1 is 1339228771545@

    It seems that WorkerScript recall the new Date().getTime() when it run the first time. Why?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      owenzhao
      wrote on last edited by
      #2

      It may related to a closed bug https://bugreports.qt-project.org/browse/QTBUG-14666
      I also file a bug myself.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        owenzhao
        wrote on last edited by
        #3

        Currently , the only way is using parseInt() and toString() together, like
        @parseInt(new Date().getTime().toString())@

        1 Reply Last reply
        0
        • O Offline
          O Offline
          owenzhao
          wrote on last edited by
          #4

          This seems not working each time. A better idea is to use
          @property string t1@
          then convert it int in the test.js
          @parseInt(t1)@
          [quote author="owenzhao" date="1339232752"]Currently , the only way is using parseInt() and toString() together, like
          @parseInt(new Date().getTime().toString())@[/quote]

          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