summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.cpp
diff options
context:
space:
mode:
authorJohn Brooks <special@dereferenced.net>2010-08-12 08:14:28 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2010-08-12 08:14:28 (GMT)
commita6892d69281d3555f3c3fd03f3b3892b1940191d (patch)
tree32bf15ff4199c7b3a0e616b84486b69c3b3af7eb /src/corelib/kernel/qobject.cpp
parentcf13b06e88e68ca966d6327c0e12cc7b89d616fc (diff)
downloadQt-a6892d69281d3555f3c3fd03f3b3892b1940191d.zip
Qt-a6892d69281d3555f3c3fd03f3b3892b1940191d.tar.gz
Qt-a6892d69281d3555f3c3fd03f3b3892b1940191d.tar.bz2
Added QObject::senderSignalIndex()
Returns the metamethod index of the signal executing the current slot Merge-request: 2433 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r--src/corelib/kernel/qobject.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 9ce111d..ceffa66 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -2287,7 +2287,7 @@ static void err_info_about_objects(const char * func,
a thread different from this object's thread. Do not use this
function in this type of scenario.
- \sa QSignalMapper
+ \sa senderSignalIndex(), QSignalMapper
*/
QObject *QObject::sender() const
@@ -2307,6 +2307,47 @@ QObject *QObject::sender() const
}
/*!
+ \since 4.8
+
+ Returns the meta-method index of the signal that called the currently
+ executing slot, which is a member of the class returned by sender().
+ If called outside of a slot activated by a signal, -1 is returned.
+
+ For signals with default parameters, this function will always return
+ the index with all parameters, regardless of which was used with
+ connect(). For example, the signal \c {destroyed(QObject *obj = 0)}
+ will have two different indexes (with and without the parameter), but
+ this function will always return the index with a parameter. This does
+ not apply when overloading signals with different parameters.
+
+ \warning This function violates the object-oriented principle of
+ modularity. However, getting access to the signal index might be useful
+ when many signals are connected to a single slot.
+
+ \warning The return value of this function is not valid when the slot
+ is called via a Qt::DirectConnection from a thread different from this
+ object's thread. Do not use this function in this type of scenario.
+
+ \sa sender(), QMetaObject::indexOfSignal(), QMetaObject::method()
+*/
+
+int QObject::senderSignalIndex() const
+{
+ Q_D(const QObject);
+
+ QMutexLocker locker(signalSlotLock(this));
+ if (!d->currentSender)
+ return -1;
+
+ for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) {
+ if (c->sender == d->currentSender->sender)
+ return d->currentSender->signal;
+ }
+
+ return -1;
+}
+
+/*!
Returns the number of receivers connected to the \a signal.
Since both slots and signals can be used as receivers for signals,