summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorSze Howe Koh <szehowe.koh@gmail.com>2014-02-25 09:17:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-13 17:17:26 +0100
commit28984cd5ba63c557b88377f996a90b9665f37745 (patch)
tree9baa26a3a9cd42f7885bd0d52d4968ebc14b16fc /doc
parent912afe4f2aaef179e55fb31f4d656a693e4c367c (diff)
downloadqt4-tools-28984cd5ba63c557b88377f996a90b9665f37745.tar.gz
Doc: Discuss the concept of thread affinity in more detail
- Create a section dedicated to this concept, which is fundamental to signal/event handling - Move relevant content from the very broad "Thread Basics" page to the QObject class ref - Flesh out existing content, including distinguishing signals from events - Address the common misconception that "member" = "child"; this has been encountered several times in the Qt Project forums This is a cherry-pick from 3b45dfe6e6ff6c0626b in qtbase.git Change-Id: If3b65f3da4e1ca414c7175c4e22bcdef38f45442 Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/src/tutorials/threads.qdoc26
1 files changed, 2 insertions, 24 deletions
diff --git a/doc/src/tutorials/threads.qdoc b/doc/src/tutorials/threads.qdoc
index 055290842d..ad66b9f061 100644
--- a/doc/src/tutorials/threads.qdoc
+++ b/doc/src/tutorials/threads.qdoc
@@ -277,19 +277,9 @@
\section2 QObject and Threads
- A QObject is said to have a \e{thread affinity} or, in other words, that it
- lives in a certain thread. This means that, at creation time, QObject saves
- a pointer to the current thread. This information becomes relevant when an
- event is posted with \l{QCoreApplication::}{postEvent()}. The event will be
- put in the corresponding thread's event loop. If the thread where the
- QObject lives doesn't have an event loop, the event will never be delivered.
-
- To start an event loop, \l{QThread::}{exec()} must be called inside
- \l{QThread::}{run()}. Thread affinity can be changed using
- \l{QObject::}{moveToThread()}.
-
As mentioned above, developers must always be careful when calling objects'
- methods from other threads. Thread affinity does not change this situation.
+ methods from other threads. \l{QObject#Thread Affinity}{Thread affinity}
+ does not change this situation.
Qt documentation marks several methods as thread-safe.
\l{QCoreApplication::}{postEvent()} is a noteworthy example. A thread-safe
method may be called from different threads simultaneously.
@@ -326,18 +316,6 @@
has terminated.
\endlist
- A QObject's parent must always be in the same thread. This has a surprising
- consequence for objects generated within the \l{QThread::}{run()} method:
-
- \code
- void HelloThread::run()
- {
- QObject *object1 = new QObject(this); //error, parent must be in the same thread
- QObject object2; // OK
- QSharedPointer <QObject> object3(new QObject); // OK
- }
- \endcode
-
\section2 Using a Mutex to Protect the Integrity of Data
A mutex is an object that has \l{QMutex::}{lock()} and \l{QMutex::}{unlock()}