Developer Documentation
|
The Process interface can be used to run arbitrary slots of your plugin within a separate thread of OpenFlipper. OpenFlipper supports a process manager, visualizing currently running operations to the user. Process dialogs and user information can be provided via special signals.
As in qt user interface operations are only allowed from within the main thread, you can not interact with the ui in your threads. Feedback like the progress or other messages need to be passed through the ProcessInterface. Additionally you have to make sure, that your operations can actually run in parallel to others. If not, you have to mark your thread as blocking, which would prevent the user from starting additional operations until your job gets finished.
Using threads in OpenFlipper is quite simple. All necessary class definitions are already available to plugins. A tutorial for the thread interface is available: Using threads from within a plugin
So the first thing we have to do is instantiate an OpenFlipperThread object and tell the core that we just created a thread via ProcessInterface::startJob().
Next thing to do is connecting the thread's signal to local signals/slots in order to keep track of updates concerning the processing of our thread.
The function() signal needs to be connected to the function that will actually be processed in the thread. Once having connected these signals, we're about to start our thread:
There are two signals that you can use to inform the user about your threads state. The first is ProcessInterface::setJobState(). It gets the jobId and an int. The int is the process status. It has to be in the values that have been given with ProcessInterface::startJob() before. OpenFlipper will calculate the percentage on its own and display a progress bar at the specific position.
The second function is ProcessInterface::setJobDescription() getting a description, that can be changed wile the thread is running. The following example shows a simple thread slot,using these signals.
To use the ProcessInterface:
LoggingInterface::log()
A quick example for stating a thread:
Note: If your class is derived from OpenFlipperThread, do not reimplement the run() function. Instead, use the function(QString) to connect the your running function with Qt::DirectConnection. Short example: Be MyThread the derived thread class
and parallelFunction(QString) the function which should run by different threads.
Instead of reimplementing the run function, connect the parallelFunction(QString) with the function(QString) signal in e.g. the constructor:
Note: The OpenFlipperThread will not be notified about job cancelling. You plugin has to be aware of it.
Note: You might also want to connect the signal OpenFlipperThread::state() to the plugin's signal setJobState():
Use signal OpenFlipperThread::state() within your run() function in order to correctly update the job's state.