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

jan-arve.saether at nokia.com jan-arve.saether at nokia.com
Tue Feb 21 15:20:20 CET 2012


ext Marc Mutz wrote on 2012-02-21:
> 
> https://codereview.qt-project.org/#change,17062
> 
> The patch also nicely highlights how and where QString().sprintf() is 
> used in Qt itself, because it adjusts all callers.
> 
This caught my interest, so I checked some of the callers to see how
sprintf was used. 
It's interesting to see how lots of the callers does not need QString::sprintf().
For instance:

For instance:
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)

And lots of the callers that don't need localized strings, could have been replaced
with QByteArray::sprintf() instead (well, if the function existed).

This leads me to my question:
Is there any reason why we cannot move QString::asprintf() to QByteArray::asprintf() instead?

cheers,
Jan-Arve




More information about the Development mailing list