summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-02-20 13:54:26 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-02-12 09:58:00 +0000
commitd251cae7b7370af328307948aca9bb63def22fe4 (patch)
treee70c25f582e5e890e0886320d3899a8f460a156b /src/widgets
parent63114f4d3ce568e05346f7dba815b567da47894d (diff)
Long live QString::asprintf()!
asprintf() is a GNU extension that prints into a string it allocates internally. Arguably, that's a better name for QString::sprintf() since it also allocates memory internally. The main problem with QString::sprintf() isn't that it's dangerous to use (it is), but that it's not static. It also returns a reference instead of by-value, breaking RVO. There is a comment about removing this function completely in Qt 6.0, but it remains the only printf-style function in Qt that can allocate the target string, so it's vital for logging, e.g., and the recommended replacement code (http://linux.die.net/man/3/vsnprintf) is a nightmare. So this patch adds static (v)asprintf() methods to replace it. Further patches will fix up all in-tree callers and finally deprecate the old (v)sprintf(). Test coverage is provided through the existing tests of sprintf(), which is implemented in terms of asprintf(). Arguably, the in-tree callers show that QByteArray would benefit from having an asprintf(), too, as most of the in-tree code works around its lack with calls to to{Latin1,Local8Bit}() after using the QString version. [ChangeLog][QtCore][QString] Added asprintf(), vasprintf(). Change-Id: I8510f8d67c22230653ec0f1c252c01bc95f3c386 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index 67b53c072c..cd952737dd 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -975,7 +975,7 @@ QPixmap QItemDelegate::decoration(const QStyleOptionViewItem &option, const QVar
return qvariant_cast<QPixmap>(variant);
}
-// hacky but faster version of "QString::sprintf("%d-%d", i, enabled)"
+// hacky but faster version of "QString::asprintf("%d-%d", i, enabled)"
static QString qPixmapSerial(quint64 i, bool enabled)
{
ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', ushort('0' + enabled) };