summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/frameworks-technologies/threads.qdoc45
-rw-r--r--src/corelib/global/qnamespace.qdoc73
-rw-r--r--src/corelib/kernel/qobject.cpp2
3 files changed, 73 insertions, 47 deletions
diff --git a/doc/src/frameworks-technologies/threads.qdoc b/doc/src/frameworks-technologies/threads.qdoc
index 10da936..fd6bebb 100644
--- a/doc/src/frameworks-technologies/threads.qdoc
+++ b/doc/src/frameworks-technologies/threads.qdoc
@@ -472,24 +472,37 @@
\section1 Signals and Slots Across Threads
- Qt supports three types of signal-slot connections:
+ Qt supports these signal-slot connection types:
\list
- \o With \l{Qt::DirectConnection}{direct connections}, the
- slot gets called immediately when the signal is emitted. The
- slot is executed in the thread that emitted the signal (which
- is not necessarily the thread where the receiver object
- lives).
-
- \o With \l{Qt::QueuedConnection}{queued connections}, the
- slot 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.
-
- \o With \l{Qt::AutoConnection}{auto connections} (the default),
- the behavior is the same as with direct connections if
- the signal is emitted in the thread where the receiver lives;
- otherwise, the behavior is that of a queued connection.
+
+ \o \l{Qt::AutoConnection}{Auto Connection} (default) The behavior
+ is the same as the Direct Connection, if the emitter and
+ receiver are in the same thread. The behavior is the same as
+ the Queued Connection, if the emitter and receiver are in
+ different threads.
+
+ \o \l{Qt::DirectConnection}{Direct Connection} The slot is invoked
+ immediately, when the signal is emitted. The slot is executed
+ in the emitter's thread, which is not necessarily the
+ receiver's thread.
+
+ \o \l{Qt::QueuedConnection}{Queued Connection} The slot is invoked
+ when control returns to the event loop of the receiver's
+ thread. The slot is executed in the receiver's thread.
+
+ \o \l{Qt::BlockingQueuedConnection}{Blocking Queued Connection}
+ The slot is invoked as for the Queued Connection, except the
+ current thread blocks until the slot returns. \note Using this
+ type to connect objects in the same thread will cause deadlock.
+
+ \o \l{Qt::UniqueConnection}{Unique Connection} The behavior is the
+ same as the Auto Connection, but the connection is made only if
+ it does not duplicate an existing connection. i.e., if the same
+ signal is already connected to the same slot for the same pair
+ of objects, then the connection is not made and connect()
+ returns false.
+
\endlist
The connection type can be specified by passing an additional
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 9ef2101..871dd5c 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -514,45 +514,58 @@
/*!
\enum Qt::ConnectionType
- This enum describes the types of connection that can be used between signals and
- slots. In particular, it determines whether a particular signal is delivered to a
- slot immediately or queued for delivery at a later time.
+ This enum describes the types of connection that can be used
+ between signals and slots. In particular, it determines whether a
+ particular signal is delivered to a slot immediately or queued for
+ delivery at a later time.
+
+ \value AutoConnection
+ (default) Same as DirectConnection, if the emitter and
+ receiver are in the same thread. Same as QueuedConnection,
+ if the emitter and receiver are in different threads.
+
+ \value DirectConnection
+ The slot is invoked immediately, when the signal is
+ emitted.
+
+ \value QueuedConnection
+ The slot is invoked when control returns to the event loop
+ of the receiver's thread. The slot is executed in the
+ receiver's thread.
- \value DirectConnection When emitted, the signal is immediately delivered to the slot.
- \value QueuedConnection When emitted, the signal is queued until the event loop is
- able to deliver it to the slot.
\value BlockingQueuedConnection
- Same as QueuedConnection, except that the current thread blocks
- until the slot has been delivered. This connection type should
- only be used for receivers in a different thread. Note that misuse
- of this type can lead to deadlocks in your application.
- \value AutoConnection If the signal is emitted from the thread
- in which the receiving object lives, the
- slot is invoked directly, as with
- Qt::DirectConnection; otherwise the
- signal is queued, as with
- Qt::QueuedConnection.
- \value UniqueConnection Same as AutoConnection, but there will be a check that the signal is
- not already connected to the same slot before connecting, otherwise,
- the connection will fail.
- This value was introduced in Qt 4.6.
+ Same as QueuedConnection, except the current thread blocks
+ until the slot returns. This connection type should only be
+ used where the emitter and receiver are in different
+ threads. \note Violating this rule can cause your
+ application to deadlock.
+
+ \value UniqueConnection
+ Same as AutoConnection, but the connection is made only if
+ it does not duplicate an existing connection. i.e., if the
+ same signal is already connected to the same slot for the
+ same pair of objects, then the connection will fail. This
+ connection type was introduced in Qt 4.6.
+
\value AutoCompatConnection
- The default connection type for signals and slots when Qt 3 support
- is enabled. Equivalent to AutoConnection for connections but will cause warnings
- to be output under certain circumstances. See
- \l{Porting to Qt 4#Compatibility Signals and Slots}{Compatibility Signals and Slots}
- for further information.
+ The default type when Qt 3 support is enabled. Same as
+ AutoConnection but will also cause warnings to be output in
+ certain situations. See \l{Porting to Qt 4#Compatibility
+ Signals and Slots}{Compatibility Signals and Slots} for
+ further information.
- With queued connections, the parameters must be of types that are known to
- Qt's meta-object system, because Qt needs to copy the arguments to store them
- in an event behind the scenes. If you try to use a queued connection and
- get the error message
+ With queued connections, the parameters must be of types that are
+ known to Qt's meta-object system, because Qt needs to copy the
+ arguments to store them in an event behind the scenes. If you try
+ to use a queued connection and get the error message:
\snippet doc/src/snippets/code/doc_src_qnamespace.qdoc 0
- call qRegisterMetaType() to register the data type before you
+ Call qRegisterMetaType() to register the data type before you
establish the connection.
+ When using signals and slots with multiple threads, see \l{Signals and Slots Across Threads}.
+
\sa {Thread Support in Qt}, QObject::connect(), qRegisterMetaType()
*/
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 3564a35..8346fe4 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -2456,7 +2456,7 @@ int QObject::receivers(const char *signal) const
If you pass the Qt::UniqueConnection \a type, the connection will only
be made if it is not a duplicate. If there is already a duplicate
(exact same signal to the exact same slot on the same objects),
- the connection will fail and connect will return false
+ the connection will fail and connect will return false.
The optional \a type parameter describes the type of connection
to establish. In particular, it determines whether a particular