summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-08-13 20:37:59 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-08-13 20:37:59 (GMT)
commitcccf8e7d8df2dfe537d3194e6e0becfc1671b0c0 (patch)
tree626b3625eb75bc9e3e87817b5d02c5b4e367e8fc /src/corelib/kernel
parent36b56ef1b0034758fa6ade302177365ebce9899a (diff)
parent3411ac72ffcbd8152342603152193aa7283bd149 (diff)
downloadQt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.zip
Qt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.tar.gz
Qt-cccf8e7d8df2dfe537d3194e6e0becfc1671b0c0.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: Cannot enter text through character viewer on Mac (Cocoa) QNAM HTTP: Remove eatWhitespace() hack QNAM: Fix namespaced compilation Revert the addition of the test of QtTest's random feature. QAbstractSocket: Remove warning QNAM Zerocopy: Benchmark tst_qbytearray: Auto test for reserve() tst_qiodevice: Add peek()ing auto test tst_qnetworkreply: Zerocopy auto test tst_qhttpnetworkconnection: Pipelining auto test QNAM Zerocopy: QNAM implementation part QNAM Zerocopy: HTTP implementation part QAbstractSocket: Enable Unbuffered OpenMode for TCP QNativeSocketEngine: Fix wrong debug output Added QObject::senderSignalIndex() Cleanup the connection list logic in QObject::sender Fixed linking against libQtTest on Mac. Added -random option to tests, making the test cases within a test execute in arbitrary order. Very useful for avoiding test cases being dependent on the running order.
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qobject.cpp56
-rw-r--r--src/corelib/kernel/qobject.h1
2 files changed, 49 insertions, 8 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 143dbff..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
@@ -2298,13 +2298,53 @@ QObject *QObject::sender() const
if (!d->currentSender)
return 0;
- // Return 0 if d->currentSender isn't in d->senders
- bool found = false;
- for (QObjectPrivate::Connection *c = d->senders; c && !found; c = c->next)
- found = (c->sender == d->currentSender->sender);
- if (!found)
- return 0;
- return d->currentSender->sender;
+ for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) {
+ if (c->sender == d->currentSender->sender)
+ return d->currentSender->sender;
+ }
+
+ return 0;
+}
+
+/*!
+ \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;
}
/*!
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 21bad16..b5db936 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -280,6 +280,7 @@ public Q_SLOTS:
protected:
QObject *sender() const;
+ int senderSignalIndex() const;
int receivers(const char* signal) const;
virtual void timerEvent(QTimerEvent *);