From 7129ec0f476f33f32760e4b7801adaae14164444 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 24 Feb 2014 09:29:41 +0100 Subject: [PATCH] Document qPrintable encoding issues Change-Id: I8936203afaa100ac4665ed668f7729fc8da1d445 Reviewed-by: Oswald Buddenhagen Reviewed-by: Jerome Pasion --- src/corelib/global/qglobal.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index fe10c493a7..0f1968d151 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2810,12 +2810,17 @@ int qrand() The char pointer will be invalid after the statement in which qPrintable() is used. This is because the array returned by - toLocal8Bit() will fall out of scope. + QString::toLocal8Bit() will fall out of scope. Example: \snippet code/src_corelib_global_qglobal.cpp 37 + \note qDebug(), qWarning(), qCritical(), qFatal() expect %s + arguments to be UTF-8 encoded, while qPrintable() converts to + local 8-bit encoding. Therefore using qPrintable for logging + strings is only safe if the argument contains only ASCII + characters. \sa qDebug(), qWarning(), qCritical(), qFatal() */