File: qthread.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (348 lines) | stat: -rw-r--r-- 33,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qthread.cpp -->
  <title>Qt 4.8: QThread Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtcore.html">QtCore</a></li>
<li>QThread</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#public-slots">Public Slots</a></li>
<li class="level1"><a href="#signals">Signals</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#static-protected-members">Static Protected Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QThread Class Reference</h1>
<!-- $$$QThread-brief -->
<p>The QThread class provides platform-independent threads. <a href="#details">More...</a></p>
<!-- @@@QThread -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QThread&gt;</span></pre><p><b>Inherits: </b><a href="qobject.html">QObject</a>.</p>
<p><b>Inherited by: </b></p>
<ul>
<li><a href="qthread-members.html">List of all members, including inherited members</a></li>
<li><a href="qthread-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#Priority-enum">Priority</a></b> { IdlePriority, LowestPriority, LowPriority, NormalPriority, ..., InheritPriority }</td></tr>
</table>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#QThread">QThread</a></b> ( QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#dtor.QThread">~QThread</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#exit">exit</a></b> ( int <i>returnCode</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#isFinished">isFinished</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#isRunning">isRunning</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Priority </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#priority">priority</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setPriority">setPriority</a></b> ( Priority <i>priority</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setStackSize">setStackSize</a></b> ( uint <i>stackSize</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> uint </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#stackSize">stackSize</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#wait">wait</a></b> ( unsigned long <i>time</i> = ULONG_MAX )</td></tr>
</table>
<ul>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="public-slots"></a>
<h2>Public Slots</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#quit">quit</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#start">start</a></b> ( Priority <i>priority</i> = InheritPriority )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#terminate">terminate</a></b> ()</td></tr>
</table>
<ul>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
</ul>
<a name="signals"></a>
<h2>Signals</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#finished">finished</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#started">started</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#terminated">terminated</a></b> ()</td></tr>
</table>
<ul>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2>Static Public Members</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QThread * </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#currentThread">currentThread</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Qt::HANDLE </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#currentThreadId">currentThreadId</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#idealThreadCount">idealThreadCount</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#yieldCurrentThread">yieldCurrentThread</a></b> ()</td></tr>
</table>
<ul>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h2>Protected Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#exec">exec</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#run">run</a></b> ()</td></tr>
</table>
<ul>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="static-protected-members"></a>
<h2>Static Protected Members</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#msleep">msleep</a></b> ( unsigned long <i>msecs</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a></b> ( bool <i>enabled</i> = true )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#sleep">sleep</a></b> ( unsigned long <i>secs</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qthread.html#usleep">usleep</a></b> ( unsigned long <i>usecs</i> )</td></tr>
</table>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QThread-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>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 <tt>main()</tt>, QThreads begin executing in <a href="qthread.html#run">run</a>(). By default, <a href="qthread.html#run">run</a>() starts the event loop by calling <a href="qthread.html#exec">exec</a>() (see below). To create your own threads, subclass QThread and reimplement <a href="qthread.html#run">run</a>(). For example:</p>
<pre class="cpp"> <span class="keyword">class</span> MyThread : <span class="keyword">public</span> <span class="type">QThread</span>
 {
 <span class="keyword">public</span>:
     <span class="type">void</span> run();
 };

 <span class="type">void</span> MyThread<span class="operator">::</span><a href="qthread.html#run">run</a>()
 {
     <span class="type"><a href="qtcpsocket.html">QTcpSocket</a></span> socket;
     <span class="comment">// connect QTcpSocket's signals somewhere meaningful</span>
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
     socket<span class="operator">.</span>connectToHost(hostName<span class="operator">,</span> portNumber);
     exec();
 }</pre>
<p>This will create a <a href="qtcpsocket.html">QTcpSocket</a> in the thread and then execute the thread's event loop. Use the <a href="qthread.html#start">start</a>() method to begin execution. Execution ends when you return from <a href="qthread.html#run">run</a>(), just as an application does when it leaves main(). QThread will notifiy you via a signal when the thread is <a href="qthread.html#started">started</a>(), <a href="qthread.html#finished">finished</a>(), and <a href="qthread.html#terminated">terminated</a>(), or you can use <a href="qthread.html#isFinished">isFinished</a>() and <a href="qthread.html#isRunning">isRunning</a>() to query the state of the thread. Use <a href="qthread.html#wait">wait</a>() to block until the thread has finished execution.</p>
<p>Each thread gets its own stack from the operating system. The operating system also determines the default size of the stack. You can use <a href="qthread.html#setStackSize">setStackSize</a>() to set a custom stack size.</p>
<p>Each QThread can have its own event loop. You can start the event loop by calling <a href="qthread.html#exec">exec</a>(); you can stop it by calling <a href="qthread.html#exit">exit</a>() or <a href="qthread.html#quit">quit</a>(). Having an event loop in a thread makes it possible to connect signals from other threads to slots in this thread, using a mechanism called <a href="qt.html#ConnectionType-enum">queued connections</a>. It also makes it possible to use classes that require the event loop, such as <a href="qtimer.html">QTimer</a> and <a href="qtcpsocket.html">QTcpSocket</a>, in the thread. Note, however, that it is not possible to use any widget classes in the thread.</p>
<p>In extreme cases, you may want to forcibly <a href="qthread.html#terminate">terminate</a>() an executing thread. However, doing so is dangerous and discouraged. Please read the documentation for <a href="qthread.html#terminate">terminate</a>() and <a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a>() for detailed information.</p>
<p>The static functions <a href="qthread.html#currentThreadId">currentThreadId</a>() and <a href="qthread.html#currentThread">currentThread</a>() return identifiers for the currently executing thread. The former returns a platform specific ID for the thread; the latter returns a QThread pointer.</p>
<p>QThread also provides platform independent sleep functions in varying resolutions. Use <a href="qthread.html#sleep">sleep</a>() for full second resolution, <a href="qthread.html#msleep">msleep</a>() for millisecond resolution, and <a href="qthread.html#usleep">usleep</a>() for microsecond resolution.</p>
</div>
<p><b>See also </b><a href="threads.html">Thread Support in Qt</a>, <a href="qthreadstorage.html">QThreadStorage</a>, <a href="qmutex.html">QMutex</a>, <a href="qsemaphore.html">QSemaphore</a>, <a href="qwaitcondition.html">QWaitCondition</a>, <a href="threads-mandelbrot.html">Mandelbrot Example</a>, <a href="threads-semaphores.html">Semaphores Example</a>, and <a href="threads-waitconditions.html">Wait Conditions Example</a>.</p>
<!-- @@@QThread -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Priority$$$IdlePriority$$$LowestPriority$$$LowPriority$$$NormalPriority$$$HighPriority$$$HighestPriority$$$TimeCriticalPriority$$$InheritPriority -->
<h3 class="fn"><a name="Priority-enum"></a>enum QThread::<span class="name">Priority</span></h3>
<p>This enum type indicates how the operating system should schedule newly created threads.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QThread::IdlePriority</tt></td><td class="topAlign"><tt>0</tt></td><td class="topAlign">scheduled only when no other threads are running.</td></tr>
<tr><td class="topAlign"><tt>QThread::LowestPriority</tt></td><td class="topAlign"><tt>1</tt></td><td class="topAlign">scheduled less often than LowPriority.</td></tr>
<tr><td class="topAlign"><tt>QThread::LowPriority</tt></td><td class="topAlign"><tt>2</tt></td><td class="topAlign">scheduled less often than NormalPriority.</td></tr>
<tr><td class="topAlign"><tt>QThread::NormalPriority</tt></td><td class="topAlign"><tt>3</tt></td><td class="topAlign">the default priority of the operating system.</td></tr>
<tr><td class="topAlign"><tt>QThread::HighPriority</tt></td><td class="topAlign"><tt>4</tt></td><td class="topAlign">scheduled more often than NormalPriority.</td></tr>
<tr><td class="topAlign"><tt>QThread::HighestPriority</tt></td><td class="topAlign"><tt>5</tt></td><td class="topAlign">scheduled more often than HighPriority.</td></tr>
<tr><td class="topAlign"><tt>QThread::TimeCriticalPriority</tt></td><td class="topAlign"><tt>6</tt></td><td class="topAlign">scheduled as often as possible.</td></tr>
<tr><td class="topAlign"><tt>QThread::InheritPriority</tt></td><td class="topAlign"><tt>7</tt></td><td class="topAlign">use the same priority as the creating thread. This is the default.</td></tr>
</table>
<!-- @@@Priority -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QThread[overload1]$$$QThreadQObject* -->
<h3 class="fn"><a name="QThread"></a>QThread::<span class="name">QThread</span> ( <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Constructs a new thread with the given <i>parent</i>. The thread does not begin executing until <a href="qthread.html#start">start</a>() is called.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>().</p>
<!-- @@@QThread -->
<!-- $$$~QThread[overload1]$$$~QThread -->
<h3 class="fn"><a name="dtor.QThread"></a>QThread::<span class="name">~QThread</span> ()</h3>
<p>Destroys the thread.</p>
<p>Note that deleting a <a href="qthread.html">QThread</a> object will not stop the execution of the thread it represents. Deleting a running <a href="qthread.html">QThread</a> (i.e&#x2e; <a href="qthread.html#isFinished">isFinished</a>() returns false) will probably result in a program crash. You can <a href="qthread.html#wait">wait</a>() on a thread to make sure that it has finished.</p>
<!-- @@@~QThread -->
<!-- $$$currentThread[overload1]$$$currentThread -->
<h3 class="fn"><a name="currentThread"></a><span class="type">QThread</span> * QThread::<span class="name">currentThread</span> ()<tt> [static]</tt></h3>
<p>Returns a pointer to a <a href="qthread.html">QThread</a> which represents the currently executing thread.</p>
<!-- @@@currentThread -->
<!-- $$$currentThreadId[overload1]$$$currentThreadId -->
<h3 class="fn"><a name="currentThreadId"></a><span class="type"><a href="qt.html#HANDLE-typedef">Qt::HANDLE</a></span> QThread::<span class="name">currentThreadId</span> ()<tt> [static]</tt></h3>
<p>Returns the thread handle of the currently executing thread.</p>
<p><b>Warning:</b> The handle returned by this function is used for internal purposes and should not be used in any application code.</p>
<p><b>Warning:</b> On Windows, the returned value is a pseudo-handle for the current thread. It can't be used for numerical comparison. i.e&#x2e;, this function returns the DWORD (Windows-Thread ID) returned by the Win32 function getCurrentThreadId(), not the HANDLE (Windows-Thread HANDLE) returned by the Win32 function getCurrentThread().</p>
<!-- @@@currentThreadId -->
<!-- $$$exec[overload1]$$$exec -->
<h3 class="fn"><a name="exec"></a><span class="type">int</span> QThread::<span class="name">exec</span> ()<tt> [protected]</tt></h3>
<p>Enters the event loop and waits until <a href="qthread.html#exit">exit</a>() is called, returning the value that was passed to <a href="qthread.html#exit">exit</a>(). The value returned is 0 if <a href="qthread.html#exit">exit</a>() is called via <a href="qthread.html#quit">quit</a>().</p>
<p>It is necessary to call this function to start event handling.</p>
<p><b>See also </b><a href="qthread.html#quit">quit</a>() and <a href="qthread.html#exit">exit</a>().</p>
<!-- @@@exec -->
<!-- $$$exit[overload1]$$$exitint -->
<h3 class="fn"><a name="exit"></a><span class="type">void</span> QThread::<span class="name">exit</span> ( <span class="type">int</span> <i>returnCode</i> = 0 )</h3>
<p>Tells the thread's event loop to exit with a return code.</p>
<p>After calling this function, the thread leaves the event loop and returns from the call to <a href="qeventloop.html#exec">QEventLoop::exec</a>(). The <a href="qeventloop.html#exec">QEventLoop::exec</a>() function returns <i>returnCode</i>.</p>
<p>By convention, a <i>returnCode</i> of 0 means success, any non-zero value indicates an error.</p>
<p>Note that unlike the C library function of the same name, this function <i>does</i> return to the caller -- it is event processing that stops.</p>
<p>No QEventLoops will be started anymore in this thread until <a href="qthread.html#exec">QThread::exec</a>() has been called again. If the eventloop in <a href="qthread.html#exec">QThread::exec</a>() is not running then the next call to <a href="qthread.html#exec">QThread::exec</a>() will also return immediately.</p>
<p><b>See also </b><a href="qthread.html#quit">quit</a>() and <a href="qeventloop.html">QEventLoop</a>.</p>
<!-- @@@exit -->
<!-- $$$finished[overload1]$$$finished -->
<h3 class="fn"><a name="finished"></a><span class="type">void</span> QThread::<span class="name">finished</span> ()<tt> [signal]</tt></h3>
<p>This signal is emitted when the thread has finished executing.</p>
<p><b>See also </b><a href="qthread.html#started">started</a>() and <a href="qthread.html#terminated">terminated</a>().</p>
<!-- @@@finished -->
<!-- $$$idealThreadCount[overload1]$$$idealThreadCount -->
<h3 class="fn"><a name="idealThreadCount"></a><span class="type">int</span> QThread::<span class="name">idealThreadCount</span> ()<tt> [static]</tt></h3>
<p>Returns the ideal number of threads that can be run on the system. This is done querying the number of processor cores, both real and logical, in the system. This function returns -1 if the number of processor cores could not be detected.</p>
<!-- @@@idealThreadCount -->
<!-- $$$isFinished[overload1]$$$isFinished -->
<h3 class="fn"><a name="isFinished"></a><span class="type">bool</span> QThread::<span class="name">isFinished</span> () const</h3>
<p>Returns true if the thread is finished; otherwise returns false.</p>
<p><b>See also </b><a href="qthread.html#isRunning">isRunning</a>().</p>
<!-- @@@isFinished -->
<!-- $$$isRunning[overload1]$$$isRunning -->
<h3 class="fn"><a name="isRunning"></a><span class="type">bool</span> QThread::<span class="name">isRunning</span> () const</h3>
<p>Returns true if the thread is running; otherwise returns false.</p>
<p><b>See also </b><a href="qthread.html#isFinished">isFinished</a>().</p>
<!-- @@@isRunning -->
<!-- $$$msleep[overload1]$$$msleepunsignedlong -->
<h3 class="fn"><a name="msleep"></a><span class="type">void</span> QThread::<span class="name">msleep</span> ( <span class="type">unsigned</span> <span class="type">long</span> <i>msecs</i> )<tt> [static protected]</tt></h3>
<p>Causes the current thread to sleep for <i>msecs</i> milliseconds.</p>
<p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#usleep">usleep</a>().</p>
<!-- @@@msleep -->
<!-- $$$priority[overload1]$$$priority -->
<h3 class="fn"><a name="priority"></a><span class="type"><a href="qthread.html#Priority-enum">Priority</a></span> QThread::<span class="name">priority</span> () const</h3>
<p>Returns the priority for a running thread. If the thread is not running, this function returns <tt>InheritPriority</tt>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qthread.html#Priority-enum">Priority</a>, <a href="qthread.html#setPriority">setPriority</a>(), and <a href="qthread.html#start">start</a>().</p>
<!-- @@@priority -->
<!-- $$$quit[overload1]$$$quit -->
<h3 class="fn"><a name="quit"></a><span class="type">void</span> QThread::<span class="name">quit</span> ()<tt> [slot]</tt></h3>
<p>Tells the thread's event loop to exit with return code 0 (success). Equivalent to calling QThread::exit(0).</p>
<p>This function does nothing if the thread does not have an event loop.</p>
<p><b>See also </b><a href="qthread.html#exit">exit</a>() and <a href="qeventloop.html">QEventLoop</a>.</p>
<!-- @@@quit -->
<!-- $$$run[overload1]$$$run -->
<h3 class="fn"><a name="run"></a><span class="type">void</span> QThread::<span class="name">run</span> ()<tt> [virtual protected]</tt></h3>
<p>The starting point for the thread. After calling <a href="qthread.html#start">start</a>(), the newly created thread calls this function. The default implementation simply calls <a href="qthread.html#exec">exec</a>().</p>
<p>You can reimplemented this function to do other useful work. Returning from this method will end the execution of the thread.</p>
<p><b>See also </b><a href="qthread.html#start">start</a>() and <a href="qthread.html#wait">wait</a>().</p>
<!-- @@@run -->
<!-- $$$setPriority[overload1]$$$setPriorityPriority -->
<h3 class="fn"><a name="setPriority"></a><span class="type">void</span> QThread::<span class="name">setPriority</span> ( <span class="type"><a href="qthread.html#Priority-enum">Priority</a></span> <i>priority</i> )</h3>
<p>This function sets the <i>priority</i> for a running thread. If the thread is not running, this function does nothing and returns immediately. Use <a href="qthread.html#start">start</a>() to start a thread with a specific priority.</p>
<p>The <i>priority</i> argument can be any value in the <tt>QThread::Priority</tt> enum except for <tt>InheritPriorty</tt>.</p>
<p>The effect of the <i>priority</i> parameter is dependent on the operating system's scheduling policy. In particular, the <i>priority</i> will be ignored on systems that do not support thread priorities (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details).</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qthread.html#Priority-enum">Priority</a>, <a href="qthread.html#priority">priority</a>(), and <a href="qthread.html#start">start</a>().</p>
<!-- @@@setPriority -->
<!-- $$$setStackSize[overload1]$$$setStackSizeuint -->
<h3 class="fn"><a name="setStackSize"></a><span class="type">void</span> QThread::<span class="name">setStackSize</span> ( <span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> <i>stackSize</i> )</h3>
<p>Sets the maximum stack size for the thread to <i>stackSize</i>. If <i>stackSize</i> is greater than zero, the maximum stack size is set to <i>stackSize</i> bytes, otherwise the maximum stack size is automatically determined by the operating system.</p>
<p><b>Warning:</b> Most operating systems place minimum and maximum limits on thread stack sizes. The thread will fail to start if the stack size is outside these limits.</p>
<p><b>See also </b><a href="qthread.html#stackSize">stackSize</a>().</p>
<!-- @@@setStackSize -->
<!-- $$$setTerminationEnabled[overload1]$$$setTerminationEnabledbool -->
<h3 class="fn"><a name="setTerminationEnabled"></a><span class="type">void</span> QThread::<span class="name">setTerminationEnabled</span> ( <span class="type">bool</span> <i>enabled</i> = true )<tt> [static protected]</tt></h3>
<p>Enables or disables termination of the current thread based on the <i>enabled</i> parameter. The thread must have been started by <a href="qthread.html">QThread</a>.</p>
<p>When <i>enabled</i> is false, termination is disabled. Future calls to <a href="qthread.html#terminate">QThread::terminate</a>() will return immediately without effect. Instead, the termination is deferred until termination is enabled.</p>
<p>When <i>enabled</i> is true, termination is enabled. Future calls to <a href="qthread.html#terminate">QThread::terminate</a>() will terminate the thread normally. If termination has been deferred (i.e&#x2e; <a href="qthread.html#terminate">QThread::terminate</a>() was called with termination disabled), this function will terminate the calling thread <i>immediately</i>. Note that this function will not return in this case.</p>
<p><b>See also </b><a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@setTerminationEnabled -->
<!-- $$$sleep[overload1]$$$sleepunsignedlong -->
<h3 class="fn"><a name="sleep"></a><span class="type">void</span> QThread::<span class="name">sleep</span> ( <span class="type">unsigned</span> <span class="type">long</span> <i>secs</i> )<tt> [static protected]</tt></h3>
<p>Forces the current thread to sleep for <i>secs</i> seconds.</p>
<p><b>See also </b><a href="qthread.html#msleep">msleep</a>() and <a href="qthread.html#usleep">usleep</a>().</p>
<!-- @@@sleep -->
<!-- $$$stackSize[overload1]$$$stackSize -->
<h3 class="fn"><a name="stackSize"></a><span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> QThread::<span class="name">stackSize</span> () const</h3>
<p>Returns the maximum stack size for the thread (if set with <a href="qthread.html#setStackSize">setStackSize</a>()); otherwise returns zero.</p>
<p><b>See also </b><a href="qthread.html#setStackSize">setStackSize</a>().</p>
<!-- @@@stackSize -->
<!-- $$$start[overload1]$$$startPriority -->
<h3 class="fn"><a name="start"></a><span class="type">void</span> QThread::<span class="name">start</span> ( <span class="type"><a href="qthread.html#Priority-enum">Priority</a></span> <i>priority</i> = InheritPriority )<tt> [slot]</tt></h3>
<p>Begins execution of the thread by calling <a href="qthread.html#run">run</a>(), which should be reimplemented in a <a href="qthread.html">QThread</a> subclass to contain your code. The operating system will schedule the thread according to the <i>priority</i> parameter. If the thread is already running, this function does nothing.</p>
<p>The effect of the <i>priority</i> parameter is dependent on the operating system's scheduling policy. In particular, the <i>priority</i> will be ignored on systems that do not support thread priorities (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details).</p>
<p><b>See also </b><a href="qthread.html#run">run</a>() and <a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@start -->
<!-- $$$started[overload1]$$$started -->
<h3 class="fn"><a name="started"></a><span class="type">void</span> QThread::<span class="name">started</span> ()<tt> [signal]</tt></h3>
<p>This signal is emitted when the thread starts executing.</p>
<p><b>See also </b><a href="qthread.html#finished">finished</a>() and <a href="qthread.html#terminated">terminated</a>().</p>
<!-- @@@started -->
<!-- $$$terminate[overload1]$$$terminate -->
<h3 class="fn"><a name="terminate"></a><span class="type">void</span> QThread::<span class="name">terminate</span> ()<tt> [slot]</tt></h3>
<p>Terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating systems scheduling policies. Use <a href="qthread.html#wait">QThread::wait</a>() after terminate() for synchronous termination.</p>
<p>When the thread is terminated, all threads waiting for the thread to finish will be woken up.</p>
<p><b>Warning:</b> This function is dangerous and its use is discouraged. The thread can be terminated at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to clean up after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.</p>
<p>Termination can be explicitly enabled or disabled by calling <a href="qthread.html#setTerminationEnabled">QThread::setTerminationEnabled</a>(). Calling this function while termination is disabled results in the termination being deferred, until termination is re-enabled. See the documentation of <a href="qthread.html#setTerminationEnabled">QThread::setTerminationEnabled</a>() for more information.</p>
<p><b>See also </b><a href="qthread.html#setTerminationEnabled">setTerminationEnabled</a>().</p>
<!-- @@@terminate -->
<!-- $$$terminated[overload1]$$$terminated -->
<h3 class="fn"><a name="terminated"></a><span class="type">void</span> QThread::<span class="name">terminated</span> ()<tt> [signal]</tt></h3>
<p>This signal is emitted when the thread is terminated.</p>
<p><b>See also </b><a href="qthread.html#started">started</a>() and <a href="qthread.html#finished">finished</a>().</p>
<!-- @@@terminated -->
<!-- $$$usleep[overload1]$$$usleepunsignedlong -->
<h3 class="fn"><a name="usleep"></a><span class="type">void</span> QThread::<span class="name">usleep</span> ( <span class="type">unsigned</span> <span class="type">long</span> <i>usecs</i> )<tt> [static protected]</tt></h3>
<p>Causes the current thread to sleep for <i>usecs</i> microseconds.</p>
<p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#msleep">msleep</a>().</p>
<!-- @@@usleep -->
<!-- $$$wait[overload1]$$$waitunsignedlong -->
<h3 class="fn"><a name="wait"></a><span class="type">bool</span> QThread::<span class="name">wait</span> ( <span class="type">unsigned</span> <span class="type">long</span> <i>time</i> = ULONG_MAX )</h3>
<p>Blocks the thread until either of these conditions is met:</p>
<ul>
<li>The thread associated with this <a href="qthread.html">QThread</a> object has finished execution (i.e&#x2e; when it returns from <a href="qthread.html#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>
<li><i>time</i> milliseconds has elapsed. If <i>time</i> is ULONG_MAX (the default), then the wait will never timeout (the thread must return from <a href="qthread.html#run">run</a>()). This function will return false if the wait timed out.</li>
</ul>
<p>This provides similar functionality to the POSIX <tt>pthread_join()</tt> function.</p>
<p><b>See also </b><a href="qthread.html#sleep">sleep</a>() and <a href="qthread.html#terminate">terminate</a>().</p>
<!-- @@@wait -->
<!-- $$$yieldCurrentThread[overload1]$$$yieldCurrentThread -->
<h3 class="fn"><a name="yieldCurrentThread"></a><span class="type">void</span> QThread::<span class="name">yieldCurrentThread</span> ()<tt> [static]</tt></h3>
<p>Yields execution of the current thread to another runnable thread, if any. Note that the operating system decides to which thread to switch.</p>
<!-- @@@yieldCurrentThread -->
</div>
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>