Qt 4.8
Public Functions | Properties | Friends | List of all members
QRunnable Class Referenceabstract

The QRunnable class is the base class for all runnable objects. More...

#include <qrunnable.h>

Inheritance diagram for QRunnable:
QHostInfoRunnable

Public Functions

bool autoDelete () const
 Returns true is auto-deletion is enabled; false otherwise. More...
 
 QRunnable ()
 Constructs a QRunnable. More...
 
virtual void run ()=0
 Implement this pure virtual function in your subclass. More...
 
void setAutoDelete (bool _autoDelete)
 Enables auto-deletion if autoDelete is true; otherwise auto-deletion is disabled. More...
 
virtual ~QRunnable ()
 QRunnable virtual destructor. More...
 

Properties

int ref
 

Friends

class QThreadPool
 
class QThreadPoolPrivate
 
class QThreadPoolThread
 

Detailed Description

The QRunnable class is the base class for all runnable objects.

Since
4.4

The QRunnable class is an interface for representing a task or piece of code that needs to be executed, represented by your reimplementation of the run() function.

You can use QThreadPool to execute your code in a separate thread. QThreadPool deletes the QRunnable automatically if autoDelete() returns true (the default). Use setAutoDelete() to change the auto-deletion flag.

QThreadPool supports executing the same QRunnable more than once by calling QThreadPool::tryStart(this) from within the run() function. If autoDelete is enabled the QRunnable will be deleted when the last thread exits the run function. Calling QThreadPool::start() multiple times with the same QRunnable when autoDelete is enabled creates a race condition and is not recommended.

See also
QThreadPool

Definition at line 52 of file qrunnable.h.

Constructors and Destructors

◆ QRunnable()

QRunnable::QRunnable ( )
inline

Constructs a QRunnable.

Auto-deletion is enabled by default.

See also
autoDelete(), setAutoDelete()

Definition at line 63 of file qrunnable.h.

63 : ref(0) { }
int ref
Definition: qrunnable.h:54

◆ ~QRunnable()

QRunnable::~QRunnable ( )
inlinevirtual

QRunnable virtual destructor.

Definition at line 64 of file qrunnable.h.

64 { }

Functions

◆ autoDelete()

bool QRunnable::autoDelete ( ) const
inline

Returns true is auto-deletion is enabled; false otherwise.

If auto-deletion is enabled, QThreadPool will automatically delete this runnable after calling run(); otherwise, ownership remains with the application programmer.

See also
setAutoDelete(), QThreadPool

Definition at line 66 of file qrunnable.h.

Referenced by QThreadPoolPrivate::enqueueTask(), QThreadPoolThread::run(), QThreadPoolPrivate::startFrontRunnable(), QThreadPoolPrivate::startThread(), QThreadPoolPrivate::stealRunnable(), and QThreadPoolPrivate::tryStart().

66 { return ref != -1; }
int ref
Definition: qrunnable.h:54

◆ run()

QRunnable::run ( )
pure virtual

Implement this pure virtual function in your subclass.

Implemented in QHostInfoRunnable.

Referenced by QThreadPoolThread::run(), QThreadPoolPrivate::startFrontRunnable(), and QThreadPoolPrivate::stealRunnable().

◆ setAutoDelete()

bool QRunnable::setAutoDelete ( bool  autoDelete)
inline

Enables auto-deletion if autoDelete is true; otherwise auto-deletion is disabled.

If auto-deletion is enabled, QThreadPool will automatically delete this runnable after calling run(); otherwise, ownership remains with the application programmer.

Note that this flag must be set before calling QThreadPool::start(). Calling this function after QThreadPool::start() results in undefined behavior.

See also
autoDelete(), QThreadPool

Definition at line 67 of file qrunnable.h.

Referenced by QHostInfoRunnable::QHostInfoRunnable().

67 { ref = _autoDelete ? 0 : -1; }
int ref
Definition: qrunnable.h:54

Friends and Related Functions

◆ QThreadPool

friend class QThreadPool
friend

Definition at line 56 of file qrunnable.h.

◆ QThreadPoolPrivate

friend class QThreadPoolPrivate
friend

Definition at line 57 of file qrunnable.h.

◆ QThreadPoolThread

friend class QThreadPoolThread
friend

Definition at line 58 of file qrunnable.h.

Properties

◆ ref

int QRunnable::ref
private

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