source: trunk/doc/src/porting/qt4-threads.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \page qt4-threads.html
30 \title Thread Support in Qt 4
31
32 \contentspage {What's New in Qt 4}{Home}
33 \previouspage The Qt 4 Style API
34
35 Qt 4 makes it easier than ever to write multithreaded
36 applications. More classes have been made usable from non-GUI
37 threads, and the signals and slots mechanism can now be used to
38 communicate between threads.
39
40 \section1 General Overview
41
42 QThread now inherits QObject. It emits signals to indicate that
43 the thread started or finished executing, and provides a few
44 slots as well.
45
46 Each thread can now have its own event loop. The initial thread
47 starts its event loops using QCoreApplication::exec(); other
48 threads can start an event loop using QThread::exec(). Like
49 QCoreApplication, QThread also provides an
50 \l{QThread::exit()}{exit(int)} function and a
51 \l{QThread::quit()}{quit()} slot.
52
53 An event loop in a thread makes it possible for the thread to use
54 certain non-GUI Qt classes that require the presence of an event
55 loop (such as QTimer, QTcpSocket, and QProcess). It also makes it
56 possible to connect signals from any threads to slots of a
57 specific thread. When a signal is emitted, the slot isn't called
58 immediately; instead, it is invoked when control returns to the
59 event loop of the thread to which the object belongs. The slot is
60 executed in the thread where the receiver object lives. See
61 QObject::connect() for details.
62
63 Qt 4 also introduces a new synchronization class: QReadWriteLock.
64 It is similar to QMutex, except that it distinguishes between
65 "read" and "write" access to shared data and allows multiple
66 readers to access the data simultaneously. Using QReadWriteLock
67 instead of QMutex when it is possible can make multithreaded
68 programs more concurrent.
69
70 Since Qt 4, \l{implicitly shared} classes can safely be copied
71 across threads, like any other value classes. They are fully
72 reentrant. This is implemented using atomic reference counting
73 operations, which are implemented in assembly language for the
74 different platforms supported by Qt. Atomic reference counting is
75 very fast, much faster than using a mutex.
76
77 See \l{Thread Support in Qt} for more information.
78
79 \section1 Comparison with Qt 3
80
81 Earlier versions of Qt offered an option to build the library
82 without thread support. In Qt 4, threads are always enabled.
83
84 Qt 3 had a class called \c QDeepCopy that you could use to take a
85 deep copy of an implicitly shared object. In Qt 4, the atomic
86 reference counting makes this class superfluous.
87*/
Note: See TracBrowser for help on using the repository browser.