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
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:
void method();
void invalidMethod();
+
+ void comparisonOperators();
};
struct CustomType { };
QVERIFY(!method3.isValid());
}
+void tst_QMetaMethod::comparisonOperators()
+{
+ static const QMetaObject *mo = &MethodTestObject::staticMetaObject;
+ for (int x = 0; x < 2; ++x) {
+ int count = x ? mo->constructorCount() : mo->methodCount();
+ for (int i = 0; i < count; ++i) {
+ QMetaMethod method = x ? mo->constructor(i) : mo->method(i);
+ const QMetaObject *methodMo = method.enclosingMetaObject();
+ for (int j = 0; j < count; ++j) {
+ QMetaMethod other = x ? mo->constructor(j) : mo->method(j);
+ bool expectedEqual = ((methodMo == other.enclosingMetaObject())
+ && (i == j));
+ QCOMPARE(method == other, expectedEqual);
+ QCOMPARE(method != other, !expectedEqual);
+ QCOMPARE(other == method, expectedEqual);
+ QCOMPARE(other != method, !expectedEqual);
+ }
+
+ QVERIFY(method != QMetaMethod());
+ QVERIFY(QMetaMethod() != method);
+ QVERIFY(!(method == QMetaMethod()));
+ QVERIFY(!(QMetaMethod() == method));
+ }
+ }
+
+ // Constructors and normal methods with identical index should not
+ // compare equal
+ for (int i = 0; i < qMin(mo->methodCount(), mo->constructorCount()); ++i) {
+ QMetaMethod method = mo->method(i);
+ QMetaMethod constructor = mo->constructor(i);
+ QVERIFY(method != constructor);
+ QVERIFY(!(method == constructor));
+ }
+}
+
QTEST_MAIN(tst_QMetaMethod)
#include "tst_qmetamethod.moc"