summaryrefslogtreecommitdiffstats
path: root/tests/auto/qobject
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 /tests/auto/qobject
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 'tests/auto/qobject')
-rw-r--r--tests/auto/qobject/tst_qobject.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index fc38a84..abfe24b 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -1782,9 +1782,12 @@ class SuperObject : public QObject
Q_OBJECT
public:
QObject *theSender;
+ int theSignalId;
+
SuperObject()
{
theSender = 0;
+ theSignalId = 0;
}
friend class tst_QObject;
@@ -1795,16 +1798,17 @@ public slots:
void rememberSender()
{
theSender = sender();
+ theSignalId = senderSignalIndex();
}
void deleteAndRememberSender()
{
delete theSender;
- theSender = sender();
+ rememberSender();
}
signals:
+ void anotherSignal();
void theSignal();
-
};
void tst_QObject::sender()
@@ -1812,12 +1816,23 @@ void tst_QObject::sender()
{
SuperObject sender;
SuperObject receiver;
+ connect(&sender, SIGNAL(anotherSignal()),
+ &receiver, SLOT(rememberSender()));
connect(&sender, SIGNAL(theSignal()),
&receiver, SLOT(rememberSender()));
QCOMPARE(receiver.sender(), (QObject *)0);
+ QCOMPARE(receiver.senderSignalIndex(), -1);
emit sender.theSignal();
QCOMPARE(receiver.theSender, (QObject *)&sender);
QCOMPARE(receiver.sender(), (QObject *)0);
+ QCOMPARE(receiver.theSignalId,
+ sender.metaObject()->indexOfSignal("theSignal()"));
+ QCOMPARE(receiver.senderSignalIndex(), -1);
+
+ emit sender.anotherSignal();
+ QCOMPARE(receiver.theSignalId,
+ sender.metaObject()->indexOfSignal("anotherSignal()"));
+ QCOMPARE(receiver.senderSignalIndex(), -1);
}
{
@@ -1834,11 +1849,16 @@ void tst_QObject::sender()
Qt::DirectConnection);
QCOMPARE(receiver->sender(), (QObject *)0);
+ QCOMPARE(receiver->senderSignalIndex(), -1);
receiver->theSender = 0;
+ receiver->theSignalId = -1;
thread.start();
emit sender->theSignal();
QCOMPARE(receiver->theSender, (QObject *) sender);
QCOMPARE(receiver->sender(), (QObject *)0);
+ QCOMPARE(receiver->theSignalId,
+ sender->metaObject()->indexOfSignal("theSignal()"));
+ QCOMPARE(receiver->senderSignalIndex(), -1);
QVERIFY(thread.wait(10000));
delete receiver;