Zuble provides a mechanism to pass Javascript code to background threads for processing. This allows QML applications to perform background I/O operations. Each Zuble background thread has its own QJSEngine object, javascript context, and Zbl object that provides a set of methods for creating instances of Zuble core and sprocket QML objects for background threads to use.
The ZScripThread object encapsulates a background QThread object and a ZScriptWorker object that contains its own QJSEngine and Zbl objects. The ZScriptThread object runs in the creator's thread while the ZScriptWorker object runs in the background QThread. Javascript code sent from the creator thread will be executed in the background QThread.
The ZScriptThread.execScript() signal is used to send Javascript code fragments to the ZScriptWorker object for background processing. Each call to execScript results in an associated execComplete signal returned from the ZScriptThread object when execution of the background script has completed. execScript accepts three arguments:
The ZScriptThread.execComplete signal is received for each call to ZScriptThread.execScript(). It passes the following parameters:
The result of the execution must be either an object or an array of strings in order for JSON conversion to succeed. Background script functions should return one of these. The value will be undefined if JSON conversion fails or if no result is returned by the script.
Background scripts create Zuble core objects by calling the appropriate "Zbl.new..." methods. Call Zbl.newFile(), for example, to create a new ZFile object.
Background scripts create Zuble sprocket objects by first calling the Zbl.import() method once to load the Sprocket into the thread's object factory, then calling the Zbl.newObject() method for each new instance of the Sprocket object to be created.
Zbl.import() takes the following arguments:
Zbl.newObject() takes the following arguments:
The Zbl object provides timers for background threads. Pass a function to the Zbl.startTimerInterval() method and it will be called appropriately. Zbl.stopTimerInterval() will stop timers individually. Zbl.stopAllTimers() will stop all Zbl timers for this thread.
Zbl.startTimerInterval() takes the following arguments:
Background script theads can send signals to their containing ZScriptThread objects by calling the Zbl.alert() method. It takes the following arguments:
Originating threads connect signal handlers to the ZScriptThread::alert signal to receive alerts from background threads.
Zuble documentation copyright © 2019 Bob Dinitto. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Zuble is a derivative work of Qt version 5. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.