Cute Chess  0.1
Signals | Public Member Functions | Protected Member Functions | List of all members
ThreadedTask Class Reference

A long task that is executed in its own thread. More...

#include <threadedtask.h>

Inheritance diagram for ThreadedTask:
QThread

Signals

void progressValueChanged (int value)
 
void statusMessageChanged (const QString &message)
 

Public Member Functions

 ThreadedTask (const QString &title, const QString &labelText, int minimum, int maximum, QWidget *parent)
 
virtual ~ThreadedTask ()
 

Protected Member Functions

bool cancelRequested () const
 
QString humaniseTime (int sec) const
 

Additional Inherited Members

- Public Types inherited from QThread
enum  Priority
 

Detailed Description

A long task that is executed in its own thread.

ThreadedTask is the base class for tasks that can take a long time and should be executed in a separate thread. ThreadedTask automatically creates a progress dialog with a "cancel" button for the task.

The ThreadedTask class should be extended by reimplementing QThread::run() and checking for cancellation by calling cancelRequested() periodically. The subclass should also notify the progress dialog by emitting the progressValueChanged() signal.

ThreadedTask destroys itself and the progress dialog automatically after the task is finished or cancelled.

Constructor & Destructor Documentation

ThreadedTask::ThreadedTask ( const QString title,
const QString labelText,
int  minimum,
int  maximum,
QWidget parent 
)
explicit

Creates a new ThreadedTask object and initializes the progress dialog.

The progress dialog is initialized with the window title title, label text labelText, and a range from minimum to maximum. The dialog is window modal and its parent is set to parent.

ThreadedTask::~ThreadedTask ( )
virtual

Destroys the task and its progress dialog.

Member Function Documentation

bool ThreadedTask::cancelRequested ( ) const
protected

Returns true if the user had pressed the "cancel" button on the progress dialog; otherwise returns false.

The reimplementation of QThread::run() should check this value periodically and return if cancel was requested.

QString ThreadedTask::humaniseTime ( int  sec) const
protected

Returns human-readable version of the given time sec.

void ThreadedTask::progressValueChanged ( int  value)
signal

The reimplementation of QThread::run() should emit this signal periodically to keep the progress dialog informed of progress.

void ThreadedTask::statusMessageChanged ( const QString message)
signal

Subclasses should emit this signal when the status message (ie. the label text) is changed.


The documentation for this class was generated from the following files: