From 28c79d8c0bbe7d4316c52f0f6f5421c9aa724735 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Sun, 22 Apr 2012 20:47:08 +0200 Subject: Add comparison operators == and != for QMetaMethod This is done in preparation of introducing the QObject::connectNotify(QMetaMethod) function. Together with the forthcoming QMetaMethod::fromSignal() function, which returns the QMetaMethod corresponding to a Qt/C++ signal (member function), the comparison operators provide an effective way of checking which signal was connected to. Change-Id: I2de48628c4884a7174fb8574895f272cb3fe5634 Reviewed-by: Olivier Goffart Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qmetaobject.cpp | 18 ++++++++++++++++++ src/corelib/kernel/qmetaobject.h | 7 +++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 2439c22f74..359dbfcf23 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1477,6 +1477,24 @@ bool QMetaObject::invokeMethod(QObject *obj, invoked), otherwise returns false. */ +/*! \fn bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) + \since 5.0 + \relates QMetaMethod + \overload + + Returns true if method \a m1 is equal to method \a m2, + otherwise returns false. +*/ + +/*! \fn bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) + \since 5.0 + \relates QMetaMethod + \overload + + Returns true if method \a m1 is not equal to method \a m2, + otherwise returns false. +*/ + /*! \fn const QMetaObject *QMetaMethod::enclosingMetaObject() const \internal diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index 095b196dca..5204f04ca3 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -155,9 +155,16 @@ private: friend struct QMetaObject; friend struct QMetaObjectPrivate; friend class QObject; + friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2); + friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2); }; Q_DECLARE_TYPEINFO(QMetaMethod, Q_MOVABLE_TYPE); +inline bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) +{ return m1.mobj == m2.mobj && m1.handle == m2.handle; } +inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) +{ return !(m1 == m2); } + class Q_CORE_EXPORT QMetaEnum { public: -- cgit v1.2.3