summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-07-04 17:18:22 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-25 14:57:08 +0200
commit0e8279b7bcad4c639562bb034a20866d9b2e8192 (patch)
treecbe4ce14eac1518aac2a9103ed57885432392ce4 /src/corelib/kernel/qobject.h
parent06e8682cb7c29d15a2c49fbc442a1a4509876abb (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/corelib/kernel/qobject.h')
-rw-r--r--src/corelib/kernel/qobject.h6
1 files changed, 6 insertions, 0 deletions
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