Odd behavior when passing value through WorkerScript
-
Please see the code first.
main.qml
@import QtQuick 1.1Rectangle {
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 libraryWorkerScript.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?
-
It may related to a closed bug https://bugreports.qt-project.org/browse/QTBUG-14666
I also file a bug myself. -
Currently , the only way is using parseInt() and toString() together, like
@parseInt(new Date().getTime().toString())@ -
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]