Important: Please read the Qt Code of Conduct -

How to terminate or destroy WorkerScript?

  • I have one list view with list model.

    I am updating this list view from the worker thread as there is a huge data to load in the list.

    When my ListView gets destroyed then I want to stop/destroy my WorkerScript, as worker script tries to access ListModel (which is destroyed) and my application segments.

    So How should I destroy/terminate WorkerScript?


  • Just set WorkerScript.source to empty string

  • I tried to set the source to NULL in onDestroy of the List view screen but is does not work.

    I have one for loop in the Worker Script and that takes some time to finish and within this time if my list view gets destroyed then my application segments.

    If WorkerScript is in the for loop and if i set WorkerScript.source to blank string then it does not stop the WorkerScript from processing the for loop.

    What should i do on this, i am really stuck on this.

  • Can I using Qt.createComponent() in WorkerScript function?

    I'm new in Qt app.

    I wanna create dynamic image table(like in Samegame example) but it using thread to make real-time create by using workerScript.

    I known workerScript message can be passed between the new thread and the parent thread using sendMessage() and the onMessage() handler, but how with Qt function or can import in javascript.


  • All you need to do is when you exit from your list view, send a message to your script
    WorkerScript.onMessage = function(msg)
    if(msg.action == 'clear')

  • As far as I know, Workerscript processes the instruction in a separate thread. There's very little way to control that separate thread.
    Instead of trying to destroy it, you might wanna try to stop it, but in that case, the stop instruction will be queued I suppose..

    Main tactic will be to design it in such a way that the separate thread doesn't affect the app even if listView instance gets destroyed

Log in to reply