diff options
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 13 | ||||
-rw-r--r-- | src/corelib/kernel/qobject.h | 6 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 16 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index a3d5c1ed1b..9f8b766720 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4023,6 +4023,19 @@ QDebug operator<<(QDebug dbg, const QObject *o) { */ /*! + \macro Q_SET_OBJECT_NAME(Object) + \relates QObject + \since 5.0 + + This macro assigns \a Object the objectName "Object". + + It doesn't matter whether \a Object is a pointer or not, the + macro figures that out by itself. + + \sa QObject::objectName() +*/ + +/*! \typedef QObjectList \relates QObject diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 9cb5ab9099..1d2d6a6794 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -524,6 +524,12 @@ template <class T> inline const char * qobject_interface_iid() Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *); #endif +namespace QtPrivate { + inline QObject & deref_for_methodcall(QObject &o) { return o; } + inline QObject & deref_for_methodcall(QObject *o) { return *o; } +} +#define Q_SET_OBJECT_NAME(obj) QT_PREPEND_NAMESPACE(QtPrivate)::deref_for_methodcall(obj).setObjectName(QLatin1String(#obj)) + QT_END_NAMESPACE QT_END_HEADER diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 479cdd3ca8..9adc191135 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -563,14 +563,14 @@ void tst_QObject::findChildren() QTimer t121(&o12); QTimer emptyname(&o); - o.setObjectName("o"); - o1.setObjectName("o1"); - o2.setObjectName("o2"); - o11.setObjectName("o11"); - o12.setObjectName("o12"); - o111.setObjectName("o111"); - t1.setObjectName("t1"); - t121.setObjectName("t121"); + Q_SET_OBJECT_NAME(o); + Q_SET_OBJECT_NAME(o1); + Q_SET_OBJECT_NAME(o2); + Q_SET_OBJECT_NAME(o11); + Q_SET_OBJECT_NAME(o12); + Q_SET_OBJECT_NAME(o111); + Q_SET_OBJECT_NAME(t1); + Q_SET_OBJECT_NAME(t121); emptyname.setObjectName(""); QObject *op = 0; |