Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1950

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/kernel/qthread_unix.cpp:235 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QThread Class</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QThread Class Reference</h1>

<p>The QThread class provides platform-independent threads.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qthread-h.html">qthread.h</a>&gt;</tt>
<p>Inherits <a href="qt.html">Qt</a>.
<p><a href="qthread-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QThread"><b>QThread</b></a> ()</div></li>
<li><div class=fn>virtual <a href="#~QThread"><b>~QThread</b></a> ()</div></li>
<li><div class=fn>bool <a href="#wait"><b>wait</b></a> ( unsigned&nbsp;long&nbsp;time = ULONG_MAX )</div></li>
<li><div class=fn>void <a href="#start"><b>start</b></a> ()</div></li>
<li><div class=fn>bool <a href="#finished"><b>finished</b></a> () const</div></li>
<li><div class=fn>bool <a href="#running"><b>running</b></a> () const</div></li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li><div class=fn>Qt::HANDLE <a href="#currentThread"><b>currentThread</b></a> ()</div></li>
<li><div class=fn>void <a href="#postEvent"><b>postEvent</b></a> ( QObject&nbsp;*&nbsp;receiver, QEvent&nbsp;*&nbsp;event )</div></li>
<li><div class=fn>void <a href="#exit"><b>exit</b></a> ()</div></li>
</ul>
<h2>Protected Members</h2>
<ul>
<li><div class=fn>virtual void <a href="#run"><b>run</b></a> () = 0</div></li>
</ul>
<h2>Static Protected Members</h2>
<ul>
<li><div class=fn>void <a href="#sleep"><b>sleep</b></a> ( unsigned&nbsp;long&nbsp;secs )</div></li>
<li><div class=fn>void <a href="#msleep"><b>msleep</b></a> ( unsigned&nbsp;long&nbsp;msecs )</div></li>
<li><div class=fn>void <a href="#usleep"><b>usleep</b></a> ( unsigned&nbsp;long&nbsp;usecs )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QThread class provides platform-independent threads.
<p> 

<p> A QThread represents a separate thread of control within the program;
it shares data with all the other threads within the process but
executes independently in the way that a separate program does on
a multitasking operating system. Instead of starting in main(),
QThreads begin executing in <a href="#run">run</a>(). You inherit run()
to include your code. For example:
<p> <pre>
  class MyThread : public QThread {

  public:

    virtual void run();

  };

  void MyThread::<a href="#run">run</a>()
  {
    for( int count = 0; count &lt; 20; count++ ) {
      <a href="#sleep">sleep</a>( 1 );
      <a href="qapplication.html#qDebug">qDebug</a>( "Ping!" );
    }
  }

  int main()
  {
      MyThread a;
      MyThread b;
      a.<a href="#start">start</a>();
      b.<a href="#start">start</a>();
      a.<a href="#wait">wait</a>();
      b.<a href="#wait">wait</a>();
  }
  </pre>
 
<p> This will start two threads, each of which writes Ping! 20 times
to the screen and exits. The <a href="#wait">wait</a>() calls at the end of main() are
necessary because exiting main() ends the program, unceremoniously
killing all other threads. Each MyThread stops executing when it
reaches the end of MyThread::run(), just as an application does when
it leaves main().
<p> <p>See also <a href="threads.html">Thread Support in Qt</a>, <a href="environment.html">Environment Classes</a> and <a href="thread.html">Threading</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QThread"></a>QThread::QThread ()
</h3>
Constructs a new thread.  The thread does not actually begin executing
until <a href="#start">start</a>() is called.

<h3 class=fn><a name="~QThread"></a>QThread::~QThread ()<tt> [virtual]</tt>
</h3>
QThread destructor.  Note that deleting a QThread object will not stop
the execution of the thread it represents.  Deleting a running QThread
(ie. <a href="#finished">finished</a>() returns FALSE) will probably result in a program crash.
You can <a href="#wait">wait</a>() on the thread to make sure that the thread has finished.

<h3 class=fn>Qt::HANDLE <a name="currentThread"></a>QThread::currentThread ()<tt> [static]</tt>
</h3>
This returns the thread handle of the currently executing thread.  The
handle returned by this function is used for internal reasons and
should <em>not</em> be used in any application code.
On Windows, the returned value is a pseudo handle for the current thread,
and it cannot be used for numerical comparison.

<h3 class=fn>void <a name="exit"></a>QThread::exit ()<tt> [static]</tt>
</h3>
Ends the execution of the calling thread and wakes up any threads waiting
for its termination.

<h3 class=fn>bool <a name="finished"></a>QThread::finished () const
</h3>
Returns TRUE is the thread is finished; otherwise returns FALSE.

<h3 class=fn>void <a name="msleep"></a>QThread::msleep ( unsigned&nbsp;long&nbsp;msecs )<tt> [static protected]</tt>
</h3>
System independent sleep.  This causes the current thread to sleep for
<em>msecs</em> milliseconds

<h3 class=fn>void <a name="postEvent"></a>QThread::postEvent ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, <a href="qevent.html">QEvent</a>&nbsp;*&nbsp;event )<tt> [static]</tt>
</h3>
Provides a way of posting an event from a thread which is not the
event thread to an object. The <em>event</em> is put into a queue, then the
event thread is woken which then sends the event to the <em>receiver</em> object.
It is important to note that the event handler for the event, when called,
will be called from the event thread and not from the thread calling
<a href="#postEvent">QThread::postEvent</a>().
<p> Since QThread::postEvent() posts events into the event queue of <a href="qapplication.html">QApplication</a>,
you must create a QApplication object before calling QThread::postEvent().
<p> The event must be allocated on the heap since the post event queue
will take ownership of the event and delete it once it has been posted.
<p> <p>See also <a href="qapplication.html#postEvent">QApplication::postEvent</a>().

<h3 class=fn>void <a name="run"></a>QThread::run ()<tt> [pure virtual protected]</tt>
</h3> 
<p> This method is pure virtual, and it must be implemented in derived classes
in order to do useful work. Returning from this method will end execution
of the thread.
<p> <p>See also <a href="#wait">wait</a>().

<h3 class=fn>bool <a name="running"></a>QThread::running () const
</h3>
Returns TRUE if the thread is running; otherwise returns FALSE.

<h3 class=fn>void <a name="sleep"></a>QThread::sleep ( unsigned&nbsp;long&nbsp;secs )<tt> [static protected]</tt>
</h3>
System independent sleep.  This causes the current thread to sleep for
<em>secs</em> seconds.

<h3 class=fn>void <a name="start"></a>QThread::start ()
</h3>
This begins actual execution of the thread by calling <a href="#run">run</a>(),
which should be reimplemented in a QThread subclass to contain your code.
If you try to start a thread that is already running, this call will
wait until the thread has finished, and then restart the thread.

<h3 class=fn>void <a name="usleep"></a>QThread::usleep ( unsigned&nbsp;long&nbsp;usecs )<tt> [static protected]</tt>
</h3>
System independent sleep.  This causes the current thread to sleep for
<em>usecs</em> microseconds

<h3 class=fn>bool <a name="wait"></a>QThread::wait ( unsigned&nbsp;long&nbsp;time = ULONG_MAX )
</h3>
This provides similar functionality to POSIX pthread_join.  A thread
calling this will block until either of these conditions is met:
<ul>
<li> The thread associated with this QThread object has finished
execution (i.e. when it returns from <a href="#run">run</a>()).  This
function will return TRUE if the thread has finished.
It also returns TRUE if the thread has not been started yet.
<li> <em>time</em> milliseconds has elapsed.  If <em>time</em> is ULONG_MAX (the
default), then the wait will never timeout (the thread must return
from <a href="#run">run</a>()). This function will return FALSE if the wait timed
out.
</ul>

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>