import QtQuick import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Test Thread") //定时器测试 //显示时钟 Text { id: xtime x:parent.width-220 y:parent.height-30 text:"time" MouseArea { anchors.fill:parent onClicked: { timer.running = !timer.running } } } Timer { id:timer interval: 1000 triggeredOnStart:true //定时器启动后立刻触发一次 repeat: true //触发多次 running:true //定时器启动 onTriggered: { //print("onTriggered") xtime.text = Date().toString() } } //多线程任务 Rectangle { width: 200 height: 200 color: "#999999" Text { id:mytext text:"点击异步获取多线程中数据" } WorkerScript { id:myworker source: "myscript.js" //多线程访问的脚本 onMessage:(msg)=> //接收多线程处理后数据 { //print(msg.reply) mytext.text = msg.reply } } MouseArea { anchors.fill: parent onClicked: { //给任务脚本发送数据 myworker.sendMessage( { 'name':'testname', "datas":[3,5,7,9] } ) } } } }