Workerscript in qml

Source: Internet
Author: User

 

Qml workerscript Element

The workerscript element enables the use of threads in qml

 

Source: URL

Signals: onmessage

Methods: sendmessage

 

Detailed description

Use workerscript to run operations in a new thread. This is useful for running operations in the background so that the main GUI thread is not blocked.

Messages can be passed between the new thread and the parent thread using sendmessage () and the onmessage () handler.

 

Workerscript is used to generate a new thread and communicate with each other through messages.

 

Declare workerscript {ID: worker; Source: "dataloader. js"} ID and JS file path in the qml file. In this way, you can use worker in qml. sendmessage (MSG); send a message (MSG is a var variable defined in qml). In JS, workerscript is always defined in this way. onmessage = function (MSG) function, where MSG can contain multiple variables or attributes in worker MSG. Similarly, JS can also send messages to qml through workerscript. sendmessage ({SRC: SRC, data: jresult}), where onmessage in qml is responsible for receiving messages.

 

Note:

 

There are no global variables in the workerscript thread, so the following usage will occur in MSG. model. append (string);, causing thread crash.

 

VaR string = "time :";

 

Workerscript. onmessage = function (fmurl ){

If (msg. Action = 'appendcurrenttime '){

VaR DATA = {'time': new date (). totimestring ()};

MSG. model. append (string );

MSG. model. append (data );

MSG. model. Sync (); // updates the changes to the list

}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.