diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2014-11-10 11:17:28 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-01-18 19:59:27 +0100 |
commit | b2883a6acc7a8d8372a815cc91dd1a8449f25723 (patch) | |
tree | 79a8284b7d18306f71daf9a27ee4b2d588c787f5 /src/corelib/kernel/qcore_mac_objc.mm | |
parent | b8e46fce5c70c399c615e1b846076f379db173c5 (diff) |
Add QDebug support for NSObject and a few selected CoreFoundation types
Lets us print out the interface name in addition to the address when
doing:
qDebug() << myNSObject;
Unfortunately, CFTypeRef is just a typedef to void*, so we can't add a
generic overload for CFTypeRef. For now, we provide operators for
commonly used Core Foundation and Core Graphics types. Additional
types may be added using Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE.
Change-Id: I27b12ef9e62cb1be348b9771cb31657692903f6c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qcore_mac_objc.mm')
-rw-r--r-- | src/corelib/kernel/qcore_mac_objc.mm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 8ac062a154..265126dc58 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -42,6 +42,8 @@ #include <private/qcore_mac_p.h> +#include <qdebug.h> + #ifdef Q_OS_IOS #import <UIKit/UIKit.h> #endif @@ -61,6 +63,38 @@ QString QCFString::toQString(const NSString *nsstr) return toQString(reinterpret_cast<CFStringRef>(nsstr)); } +// ------------------------------------------------------------------------- + +QDebug operator<<(QDebug dbg, const NSObject *nsObject) +{ + return dbg << (nsObject ? nsObject.description.UTF8String : "NSObject(0x0)"); +} + +QDebug operator<<(QDebug dbg, CFStringRef stringRef) +{ + if (!stringRef) + return dbg << "CFStringRef(0x0)"; + + if (const UniChar *chars = CFStringGetCharactersPtr(stringRef)) + dbg << QString::fromRawData(reinterpret_cast<const QChar *>(chars), CFStringGetLength(stringRef)); + else + dbg << QString::fromCFString(stringRef); + + return dbg; +} + +// Prevents breaking the ODR in case we introduce support for more types +// later on, and lets the user override our default QDebug operators. +#define QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \ + __attribute__((weak)) Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) + +QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE); +QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE); +QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE); +QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE); + +// ------------------------------------------------------------------------- + QAppleOperatingSystemVersion qt_apple_os_version() { QAppleOperatingSystemVersion v = {0, 0, 0}; |