×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    26

    How is the context of WorkerScript defined?

    I am trying to move some computation-intensive code to a worker thread, as recommended by Nokia documents. The basic outline of the code is something like this:

    Code:
    // Test.qml
    import QtQuick 1.0
    import com.meego 1.0
    
    Page {
    	id: page
    	// ...
    
    	WorkerScript {
    		id: worker
    		source: "Worker.js"
    		onMessage: ...
    	}
    
    	DataModel {id : dataModel }
    
    	function startWorker() {
    		var msg = { page : page, test : 123, dataModel : dataModel };
    		worker.sendMessage(msg);
            }
        }
    }
    //
    With the javascript part like this
    Code:
    // in Worker.js
    WorkerScript.onMessage = function(message) {	
    	var obj = Qt.createQmlObject("QML code here", message.page, "myObject42");
    	WorkerScript.sendMessage({ result: obj});
    }
    //
    I have two problems with this code: first of all, the message from QML to JS is altered for some reason I dont understand. This is what I have in the calling QML:
    DEBUG: page Test_QMLTYPE_44(0x1fbc4f68)
    DEBUG: test 123
    DEBUG: dataModel QDeclarativeListModel(0x1fbb8ac8)

    And this is what the receiving JS code sees:
    DEBUG: page null
    DEBUG: test 123
    DEBUG: dataModel QDeclarativeListModelWorkerAgent(name = "")

    Notice that page is now NULL.


    Second, the Qt component is not available in the JS code, resulting in this error:
    TypeError: Result of expression 'Qt.createQmlObject' [undefined] is not a function
    (no, this is not due to "page" being null, the result is the same of I use dataModel as parent)


    Can anyone please tell me why this is happening?

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    26

    Re: How is the context of WorkerScript defined?

    I should probably add that I can get the app to coredump on N950 by adding Qt.createQmlObject to the message. That is:

    Code:
    var msg = { page : page, test : 123, dataModel : dataModel, oh_crap:  Qt.createQmlObject };
    worker.sendMessage(msg);

  3. #3
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How is the context of WorkerScript defined?

    Hi here the answers to your questions:
    1. page is not object you can pass to the worker script; the integer is copied and the dataModel variable is actually referring to your model trough a "proxy" object (QDeclarativeListModel).
    So definitely it works as expected.
    2. You cannot create any QObject in worker script.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    26

    Re: How is the context of WorkerScript defined?

    Thank you gnuton,

    I actually suspected this, but could not find any documentation confirming that. I hope the QML team understands that these limitations make WorkerScript useless for certain not-so-uncommon tasks.

  5. #5
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How is the context of WorkerScript defined?

    Hi tube,
    I believe those are a kind of technical limitations. BTW in case you cannot really achieve something in a different way using a worker script you can still subclass QAbstractListModel and perform operations in different a thread using C++.
    From my experience I suggest you to avoid using QAbstractTableModel with QML views since those display only the first row of your table.

Similar Threads

  1. Replies: 3
    Last Post: 2011-03-31, 09:45
  2. Is the export keyword defined in symbian
    By aasoftware in forum Symbian
    Replies: 5
    Last Post: 2010-09-02, 02:23
  3. Is it possible to remove the context pane?
    By peter.carpenter in forum Symbian
    Replies: 5
    Last Post: 2009-01-27, 22:21
  4. Where is the Nokia SMS server defined??
    By psdeepti in forum Symbian
    Replies: 3
    Last Post: 2008-08-23, 08:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •