~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qt4-threads.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/qt4-threads.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: Thread Support in Qt 4</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
    <link rel="prev" href="qt4-styles.html" />
 
15
    <link rel="contents" href="qt4-intro.html" />
 
16
</head>
 
17
<body>
 
18
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
19
<tr>
 
20
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
21
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
22
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><p>
 
23
[Previous: <a href="qt4-styles.html">The Qt 4 Style API</a>]
 
24
[<a href="qt4-intro.html">Home</a>]
 
25
</p>
 
26
<h1 align="center">Thread Support in Qt 4</h1>
 
27
<p>Qt 4 makes it easier than ever to write multithreaded applications. More classes have been made usable from non-GUI threads, and the signals and slots mechanism can now be used to communicate between threads.</p>
 
28
<a name="general-overview"></a>
 
29
<h2>General Overview</h2>
 
30
<p><a href="qthread.html">QThread</a> now inherits <a href="qobject.html">QObject</a>. It emits signals to indicate that the thread started or finished executing, and provides a few slots as well.</p>
 
31
<p>Each thread can now have its own event loop. The initial thread starts its event loops using <a href="qcoreapplication.html#exec">QCoreApplication::exec</a>(); other threads can start an event loop using <a href="qthread.html#exec">QThread::exec</a>(). Like <a href="qcoreapplication.html">QCoreApplication</a>, <a href="qthread.html">QThread</a> also provides an <a href="qthread.html#exit">exit</a>(int) function and a <a href="qthread.html#quit">quit()</a> slot.</p>
 
32
<p>An event loop in a thread makes it possible for the thread to use certain non-GUI Qt classes that require the presence of an event loop (such as <a href="qtimer.html">QTimer</a>, <a href="qtcpsocket.html">QTcpSocket</a>, and <a href="qprocess.html">QProcess</a>). It also makes it possible to connect signals from any threads to slots of a specific thread. When a signal is emitted, the slot isn't called immediately; instead, it is invoked when control returns to the event loop of the thread to which the object belongs. The slot is executed in the thread where the receiver object lives. See <a href="qobject.html#connect">QObject::connect</a>() for details.</p>
 
33
<p>Qt 4 also introduces a new synchronization class: <a href="qreadwritelock.html">QReadWriteLock</a>. It is similar to <a href="qmutex.html">QMutex</a>, except that it distinguishes between &quot;read&quot; and &quot;write&quot; access to shared data and allows multiple readers to access the data simultaneously. Using <a href="qreadwritelock.html">QReadWriteLock</a> instead of <a href="qmutex.html">QMutex</a> when it is possible can make multithreaded programs more concurrent.</p>
 
34
<p>Since Qt 4, <a href="shclass.html#implicitly-shared">implicitly shared</a> classes can safely be copied across threads, like any other value classes. They are fully reentrant. This is implemented using atomic reference counting operations, which are implemented in assembly language for the different platforms supported by Qt. Atomic reference counting is very fast, much faster than using a mutex.</p>
 
35
<p>See the <a href="threads.html">Thread Overview</a> for more information.</p>
 
36
<a name="comparison-with-qt-3"></a>
 
37
<h2>Comparison with Qt 3</h2>
 
38
<p>Earlier versions of Qt offered an option to build the library without thread support. In Qt 4, threads are always enabled.</p>
 
39
<p>Qt 3 had a class called <tt>QDeepCopy</tt> that you could use to take a deep copy of an implicitly shared object. In Qt 4, the atomic reference counting makes this class superfluous.</p>
 
40
<p>
 
41
[Previous: <a href="qt4-styles.html">The Qt 4 Style API</a>]
 
42
[<a href="qt4-intro.html">Home</a>]
 
43
</p>
 
44
<p /><address><hr /><div align="center">
 
45
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
46
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
47
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
48
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
49
</tr></table></div></address></body>
 
50
</html>