WorkerScript QML Type
官方描述:在一个Qt Quick应用程序中可以使用线程了.
Import Statement: import QtQuick .
属性:
source : url
信号:
message(jsobject msg)
使用WorkerScript在一个新线程中执行操作.再后台执行操作是很有用的,主GUI线程也不会锁定.
Message可以在新线程和父线程之间通过sendMessage()和onMessage()进行传递消息.
方法:
sendMessage(jsobject message)
案例:
功能是:鼠标点击窗口中的某一个位置,程序中的那行文本便会更新当前鼠标的XY坐标.
运行效果如下图所示:
import QtQuick 2.0 Rectangle {
width: 300; height: 300 Text {
id: myText
text: 'Click anywhere'
} WorkerScript {
id: myWorker
source: "script.js" onMessage: myText.text = messageObject.reply
} MouseArea {
anchors.fill: parent
onClicked: myWorker.sendMessage({ 'x': mouse.x, 'y': mouse.y })
}
}
The above worker script specifies a JavaScript file, "script.js", that handles the operations to be performed in the new thread. Here is script.js:
上面的worker script指定了一个javascript文件,"script.js",在这个新线程中处理将被执行的操作.下面就是这个script.js文件
WorkerScript.onMessage = function(message) {
// ... long-running operations and calculations are done here
WorkerScript.sendMessage({ 'reply': 'Mouse is at ' + message.x + ',' + message.y })
}
Worker script不能使用.导入语法:
见 Qt Quick Examples - Threading and Threaded ListModel Example.
属性文档:
source : url
这里保存着javascript文件的地址url,里面实现了WorkerScript.onMessage()处理线程操作.
信号文档:
message(jsobject msg)
This signal is emitted when a message msg is received from a worker script in another thread through a call to sendMessage().
通信句柄是onMessage.
方法文档:
sendMessage(jsobject message)
在其他线程中发送给定的消息到script 句柄.其他的worker script句柄可以接收消息,通过onMessage().
消息对象只可以包含一下的值类型:
boolean, number, string
JavaScript objects and arrays
ListModel objects (任何其他类型的 QObject* 是不被允许的.)
所有的对象和数组都被拷贝到message上.除了ListModel对象,在消息中任何被其他线程修改了的发送出来的信息 将不会再原始对象上反映出来.
WorkerScript QML Type的更多相关文章
- PinchArea QML Type
PinchArea类型是在QtQuick 1.1中添加进去的.PinchArea是一个不可见的对象,常用在与一个可见对象连接在一起,为对应的可见对象提供手势操作.enabled属性被用来去设置绑定对象 ...
- PinchEvent QML Type
PinchEvent类型在QtQuick 1.1中被添加进来.center, startCenter, previousCenter属性保存了两个触摸点之间的中心位置.scale and previo ...
- 初学QML之qmlRegisterType
qmlRegisterType 是一个可以将C++实现的类在QML中调用的,连接C++和QML的一个工具 首先来看QtAssistant的介绍 int qmlRegisterType(const ch ...
- QML Object Attributes QML对象属性
QML Object Attributes Every QML object type has a defined set of attributes. Each instance of an obj ...
- qml demo分析(threading-线程任务)
一.关键类说明 qml内置了WorkerScript组件,该组件有一个source属性,可以加载js文件,含有一个名为message的信号,意味着他有一个默认的onMessage槽函数,除此之外他还有 ...
- Qt QML referenceexamples attached Demo hacking
/********************************************************************************************* * Qt ...
- Qt qml的软件架构设计
google: qt qml application architecture 有很多资源. 1 https://www.ics.com/blog/multilayered-architecture- ...
- Import Statements 导入语句
Syntax of an Import Statement 导入语句的语法 An import statement allows clients to tell the engine which mo ...
- 创建一个QT for Android的传感器应用应用程序(摘自笔者2015年将出的《QT5权威指南》,本文为试读篇)
这个手册描述了使用Qt Quick面访的方式在Android和ios设备上开发QtQuick应用程序的方法.我们使用Qt Creator实现一个QtQuick应用程序,这个应用程序基于加速器的值 ...
随机推荐
- JAVA基础英语单词表(下)
quantity / 'kwɔntiti / 量,数量 query ...
- PHP如何取出数组最后一个元素?
<?php $array=array("first","sencond","third"); #1.echo end($array); ...
- (4/18)重学Standford_iOS7开发_框架和带属性字符串_课程笔记
第四课(干货课): (最近要复习考试,有点略跟不上节奏,这节课的内容还是比较重要的,仔细理解掌握对今后的编程会有很大影响) 本节课主要涉及到Foundation和UIKit框架,基本都是概念与API知 ...
- DataTable导入到Excel文件
; saveFileDialog.RestoreDirectory = ; , intIndex] = column.ColumnName; ...
- devm_kzalloc and kmalloc
Move resources allocated using unmanaged interface to managed devm interface So today let's talk abo ...
- [rxjs] Async, handle data over time
If I have an array, and I want to apply filter, map, forEach to it. let Observable = Rx.Observable; ...
- Swift 实现图片转字符画的功能
本文介绍一个IOS APP , 将图片转换成ASCII字符画,使用Swift语言编写. 举个例子,我们使用著名的蕾娜照片作为原图片 经APP转换后形成的字符画,我们打印出来,效果如下: 放大她的脸部可 ...
- java连接oracle的简单实例
连接oracle的时候,要导入oracle驱动的jar包. 连接的时候,有statement和preparedstatement两种,从代码中可以看出不同. example: package com. ...
- ctkPlugin插件系统实现项目插件式开发
插件式开发体会: 自开始写[大话QT]系列就开始接触渲染客户端的开发,说是开发不如更多的说是维护以及重构,在接手这块的东西之前自己还有点犹豫,因为之前我一直认为客户端嘛,没什么技术含量,总是想做比较有 ...
- oracle授权另外一个用户访问自己创建的数据对象
oracle安装好之后,有一个默认的scott用户,该用户有一个默认的emp表,怎样让新创建的用户也能够访问这个表呢? 授权xiaoming这个用户访问emp表,但是xiaoming只有select权 ...