Add QMetaMethod::fromSignal() function
authorKent Hansen <kent.hansen@nokia.com>
Sun, 22 Apr 2012 20:44:58 +0000 (22:44 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Apr 2012 08:37:02 +0000 (10:37 +0200)
commitdac23b9a5700d3736cfb1aa2dccb1643f1122827
tree82f00219fe8681a78b06bfb8c0d9fc077014a43e
parent56d4d97852b37d9d1ca73d5b7f85e3865912f3db
Add QMetaMethod::fromSignal() function

Given a member function that's a signal, returns the corresponding
QMetaMethod. Inspired by the implementation of the template-based
QObject::connect().

The primary use case for this function is to have an effective and
exact (not subject to shadowing) way of checking whether a known
signal was connected to in reimplementations of
QObject::connectNotify(QMetaMethod), avoiding string comparisons.
Example:

void MyObject::connectNotify(const QMetaMethod &signal)
{
    if (signal == QMetaMethod::fromSignal(&MyObject::mySignal)) {
        // Someone connected to mySignal ...
    }
}

Change-Id: I5e4de434275fe543c004d569dcaa9ceda3442f03
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
src/corelib/doc/snippets/code/src_corelib_kernel_qmetaobject.cpp
src/corelib/kernel/qmetaobject.cpp
src/corelib/kernel/qmetaobject.h
tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp