[Development] Strange behaviour of WorkerScript. The QQmlListModelWorkerAgent do not sync with latest update

Ben Lau xbenlau at gmail.com
Sun Jun 29 19:02:37 CEST 2014


Hi,

I found a strange behaviour of WorkerScript. The step to reproduce :

1. Pass a ListModel to WorkerScript via sendMessage()
2. Modify the ListModel
3. Pass the ListModel to same WorkerScript again vis sendMessage()

Expected result:
- The WorkerScript process the input model based on latest data

Actual result:
- The WorkerScript cached the input on first call , then it works based on
the old value.

The following code shows the problem:

import QtQuick 2.0

import QtTest 1.0


TestCase {


    ListModel {

        id : input

    }


    ListModel {

        id : output

    }


    WorkerScript {

        id : worker

        source : "worker.js"

        onMessage: {

        }

    }


    function test_script(){

        var i;

        for ( i = 0 ; i < 10;i++)

            input.append({ value : i})

                worker.sendMessage({ input : input,

                             output: output});

        wait(100);

        compare(output.count,10);


        input.clear();

        for (i = 0 ; i < 5;i++)

            input.append({ value : 10 + i})


        worker.sendMessage({ input : input,

                             output: output});

        wait(100);

        compare(input.count,5);

        compare(output.count,5);

    }


}


worker.js


WorkerScript.onMessage = function(msg) {

    // Mirror the data from input to output

    console.log("Input Agent",msg.input);

    console.log("input.count",msg.input.count);


    msg.output.clear();

    for (var i = 0 ; i < msg.input.count;i++)

        msg.output.append({ value : msg.input.get(i)})

    msg.output.sync();

    WorkerScript.sendMessage({

                               result : "Done"

                             });

}

Config: Using QtTest library 5.3.0, Qt 5.3.0

PASS   : CrashTest::initTestCase()

QDEBUG : CrashTest::test_script() qml: QQmlListModel(0x101fd29a0)

QDEBUG : CrashTest::test_script() qml: Input Agent
QQmlListModelWorkerAgent(0x10416ad80)

QDEBUG : CrashTest::test_script() qml: input.count 10

QDEBUG : CrashTest::test_script() qml: Input Agent
QQmlListModelWorkerAgent(0x10416ad80)

QDEBUG : CrashTest::test_script() qml: input.count 10

FAIL!  : CrashTest::test_script() Compared values are not the same

   Actual   (): 10

   Expected (): 5



Is it a expected behaviour? Any method to let WorkerScript to process the
latest update of input model instead of the old data?

Thank for any advise.

p.s Only tested with Qt 5.3.0 on Mac.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140630/a3104e17/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: workerscript.zip
Type: application/zip
Size: 2568 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140630/a3104e17/attachment.zip>


More information about the Development mailing list