summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-12 09:59:37 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-21 14:25:55 +0000
commit1005b7a0dec049f200baa8c14066bd3bb1512d2f (patch)
treef5be4c477b58f8ebaf16ccc80ec4da5d942118e5 /src/corelib/global/qglobal.h
parent226ce6020ee4eb0ccec744500c350cf54a39f231 (diff)
Long live qUtf16Printable()
QString::asprintf() has the ability to take a ushort* array as obtained from QString::utf16() and insert that into the output with an %ls conversion. But no-one ever used this, because just passing QString::utf16() to QString::asprintf() creates a warning about wchar_t* expected, but ushort* provided. The new qUtf16Printable() macro adds the necessary casts (via void* to prevent any "type-punned pointer" warnings) to make passing QString::utf16() to QString::asprintf() work silently. This should greatly reduce the need to do a round-trip via utf-8 just to print the contents of a QString. [ChangeLog][QtCore] Added qUtf16Printable(). Change-Id: I7ddd8d2b2a2191c9faa26aca95d49850d94b287c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r--src/corelib/global/qglobal.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 64d9f79faf..9b8029990c 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -687,6 +687,15 @@ Q_CORE_EXPORT bool qSharedBuild() Q_DECL_NOTHROW;
# define qUtf8Printable(string) QString(string).toUtf8().constData()
#endif
+/*
+ Wrap QString::utf16() with enough casts to allow passing it
+ to QString::asprintf("%ls") without warnings.
+*/
+#ifndef qUtf16Printable
+# define qUtf16Printable(string) \
+ static_cast<const wchar_t*>(static_cast<const void*>(QString(string).utf16()))
+#endif
+
class QString;
Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);