diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-07-04 17:18:22 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-25 14:57:08 +0200 |
commit | 0e8279b7bcad4c639562bb034a20866d9b2e8192 (patch) | |
tree | cbe4ce14eac1518aac2a9103ed57885432392ce4 /src | |
parent | 06e8682cb7c29d15a2c49fbc442a1a4509876abb (diff) |
QObject: add a macro for conveniently setting the object name
This is a simplified port of KDTools' KDAB_SET_OBJECT_NAME.
It simply assigns the variable name as the objectName of
a QObject, uic-style. It uses a small helper function so
that it works on references as well as pointer variables.
QLabel label;
QLabel *pLabel = new QLabel();
Q_SET_OBJECT_NAME(label);
Q_SET_OBJECT_NAME(pLabel);
Change-Id: I25fec0c90f33249a3ea5d2dd622ab708019fd101
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 13 | ||||
-rw-r--r-- | src/corelib/kernel/qobject.h | 6 |
2 files changed, 19 insertions, 0 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 |