summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.cpp
diff options
context:
space:
mode:
authorSze Howe Koh <szehowe.koh@gmail.com>2025-02-26 15:59:52 +0800
committerSze Howe Koh <szehowe.koh@gmail.com>2025-02-27 14:21:06 +0800
commitf5b874fd2d393b783dad85c95a158383420e481a (patch)
treefffa494f6650742657c511be840a99bf201fc6bc /src/corelib/kernel/qobject.cpp
parent6fb39ca2cbb111469ce09c8342997eb5375e3239 (diff)
[Doc] QObject: Sync warnings of isSignalConnected() and receivers()
Extends e75c1a00e31723f1c9deb8427725fa0a58fae2a8 because calling receivers() in disconnectNotify() can deadlock too. As a drive-by, some statements are generalized further: * "expensive initialization" -> "expensive operations" since that is what the relevant snippets actually show. * The potential race condition is not limited to "after this function returns and before the signal gets emitted" Task-number: QTBUG-106025 Change-Id: Iff014706b9e8d8147e3bbb9ac51542197eec5db3 Pick-to: 6.9 6.8 6.5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r--src/corelib/kernel/qobject.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 48baa96e104..54857f9f307 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -2735,10 +2735,16 @@ int QObject::senderSignalIndex() const
\snippet code/src_corelib_kernel_qobject.cpp 21
+ As the code snippet above illustrates, you can use this function to avoid
+ expensive operations or emitting a signal that nobody listens to.
+
+ \warning In a multithreaded application, consecutive calls to this
+ function are not guaranteed to yield the same results.
+
\warning This function violates the object-oriented principle of
- modularity. However, it might be useful when you need to perform
- expensive initialization only if something is connected to a
- signal.
+ modularity. In particular, this function must not be called from an
+ override of connectNotify() or disconnectNotify(), as those might get
+ called from any thread.
\sa isSignalConnected()
*/
@@ -2795,14 +2801,17 @@ int QObject::receivers(const char *signal) const
\snippet code/src_corelib_kernel_qobject.cpp 49
As the code snippet above illustrates, you can use this function to avoid
- expensive initialization or emitting a signal that nobody listens to.
- However, in a multithreaded application, connections might change after
- this function returns and before the signal gets emitted.
+ expensive operations or emitting a signal that nobody listens to.
+
+ \warning In a multithreaded application, consecutive calls to this
+ function are not guaranteed to yield the same results.
\warning This function violates the object-oriented principle of
modularity. In particular, this function must not be called from an
override of connectNotify() or disconnectNotify(), as those might get
called from any thread.
+
+ \sa receivers()
*/
bool QObject::isSignalConnected(const QMetaMethod &signal) const
{
@@ -3486,8 +3495,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
\warning This function violates the object-oriented principle of
modularity. However, it might be useful when you need to perform
- expensive initialization only if something is connected to a
- signal.
+ an expensive operation only if something is connected to a signal.
\warning This function is called from the thread which performs the
connection, which may be a different thread from the thread in which