[Development] Deprecating QString::{v,}sprintf()

Andreas Aardal Hanssen andreas at hanssen.name
Tue Feb 21 16:36:58 CET 2012

2012/2/21 <jan-arve.saether at nokia.com>

> return QString::asprintf("%d bytes", int(number));
> should be:
> return tr("%n bytes", 0, number);
> Same here:
> const QString num = QString::asprintf("%.1f KB/s", bytesPerSecond /
> 1024.0);
> should be:
> const QString num = tr("%1 KB/s").arg(bytesPerSecond/1024.0, 0, 'f', 1);
> ...And the list goes on (I stopped at qmap.cpp)

I don't know if this is really the right comparison, both are slower and
harder to understand.

sprintf() is great for formatted output, much better than chaining .args().
It also has the potential for being a lot faster.

It sounds like a step in the wrong direction to remove QString::sprintf()
and friends without adding something better.

The purpose of the function is, after all, to allow construction of
formatted output without concatenating substrings.

Andreas Aardal Hanssen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120221/5470721f/attachment.html>

More information about the Development mailing list