PDA

View Full Version : QString equivalent to sprint( str, "%hd",...)



Rayven
29th September 2009, 04:27
Is there an equivalent to sprintf( str, "%hd", intToShort) for QString::arg? I noticed in the docs that QString::sprintf does not support the %h flag, but is there a way to write the short?

Thanks

caduel
29th September 2009, 07:34
just use QString("....%1....").arg(x); while this will probably use the int overload, this will work.

luf
29th September 2009, 07:37
signed short int shi = 10;
unsigned short int usi = 11;
signed long int sli = 12;
unsigned long int uli = 13;
QString qs = "Hello World";

QString mystring = QString("%1 - %2 - %3 - %4 - %5").arg(shi).arg(usi).arg(sli).arg(uli).arg(qs);

This will result in:
10 - 11 - 12 - 13 - Hello World

Just as easy as that. If you need to make sure data is short and not long, double or other, you should typecast or convert instead of relying on %h from sprintf.

wysota
29th September 2009, 09:09
If you need to make sure data is short and not long, double or other, you should typecast or convert instead of relying on %h from sprintf.

... or use additional parameters to QString::arg().