com.trolltech.qt
Class QThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.trolltech.qt.QThread
All Implemented Interfaces:
java.lang.Runnable

public final class QThread
extends java.lang.Thread

The QThread class extends the java.lang.Thread class and should be used when QObjects are used in threads. QObjects have object affinity, meaning that they belong to a given thread, accessible through their thread() method. It is only allowed to access a QObject from the thread it belongs to. To make this work together with garbage collection the class QThread has been introduced to ensure that the native resources used by QObjects are freed when the garbage collector is run. This is implemented by the garbage collector thread posting an event to the native QObject to delete itself when the threads event loop is idle. Before exiting the thread will do flush all events, causing all native QObjects to be deleted. The QThread class also adds two convenience signals, starting and finished. Started is emitted just before the runnable target is invoked. Finished is emitted just before the thread shuts down; after the execution of the runnable target and after the flushing of the event loop.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 QSignalEmitter.Signal0 finished
          The finished signal is emitted after the QThread has finished executing its runnable target.
 QSignalEmitter.Signal0 starting
          The starting signal is emitted when before the QThread invokes its runnable target.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
QThread(java.lang.Runnable target)
          Creates a new QThread with the specified invokable target
QThread(java.lang.Runnable target, java.lang.String name)
          Creates a new QThread with the specified invokable target and the given name.
QThread(java.lang.ThreadGroup group, java.lang.Runnable target)
          Creates a new QThread with the specified invokable target and thread group.
QThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
          Creates a new QThread with the specified invokable target, name and thread group.
QThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name, long stackSize)
          Creates a new QThread with the specified invokable target, name, thread group and stack size.
 
Method Summary
 void run()
          Called by the thread to invoke the runnable target.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

starting

public QSignalEmitter.Signal0 starting
The starting signal is emitted when before the QThread invokes its runnable target. The signal is emitted from the running thread.


finished

public QSignalEmitter.Signal0 finished
The finished signal is emitted after the QThread has finished executing its runnable target. The signal is emitted from the running thread.

Constructor Detail

QThread

public QThread(java.lang.Runnable target)
Creates a new QThread with the specified invokable target

Parameters:
target - The invokable target.

QThread

public QThread(java.lang.ThreadGroup group,
               java.lang.Runnable target)
Creates a new QThread with the specified invokable target and thread group.

Parameters:
group - The thread group.
target - The target.

QThread

public QThread(java.lang.Runnable target,
               java.lang.String name)
Creates a new QThread with the specified invokable target and the given name.

Parameters:
target - The invokable target.
name - The name.

QThread

public QThread(java.lang.ThreadGroup group,
               java.lang.Runnable target,
               java.lang.String name)
Creates a new QThread with the specified invokable target, name and thread group.

Parameters:
group - The Thread group
target - The invokable target
name - The name.

QThread

public QThread(java.lang.ThreadGroup group,
               java.lang.Runnable target,
               java.lang.String name,
               long stackSize)
Creates a new QThread with the specified invokable target, name, thread group and stack size.

Parameters:
group - The Thread group
target - The invokable target
name - The name.
stackSize - The stack size.
Method Detail

run

public void run()
Called by the thread to invoke the runnable target. This method emits starting before the runnable is called and finished after the runnable is called. After the runnable is called and before finished is emitted the thread will flush any pending events in this thread. This will ensure cleanup of objects that are deleted via disposeLater() or similar.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
QObject.disposeLater()