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, i.e., instances of classes that inherit from QObject, are used in threads. Thread may be used for all other classes that inherit from QtJambiObject.

QObjects have object affinity, i.e., they belong to a given thread, which is accessed through their thread() method. It is only allowed to access a QObject from the thread to which it belongs.

The QThread class was introduced to ensure that native resources are freed when QObjects are garbage collected. The garbage collector thread posts an event to the native QObject, which then deletes itself. Before exiting, the thread will flush all events - causing all native QObjects to be deleted.

QThread has 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 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()