[Qt-interest] Problem with QString.arg()

Alexandre Beraud aberaud at infflux.com
Wed Apr 8 17:40:50 CEST 2009


Hi,

I don't see the point in using only %1 (no %2, %3...) with 4 arguments.
Maybe try QString::leftJustified()
For example: QString::number(i).leftJustified(2, '0');

Regards,

Alex



Allen, Matthew a écrit :
>
> I’m getting this error from the compiler:
>
> pdf_viewer.cpp:697: error: ISO C++ says that these are ambiguous, even 
> though the worst conversion for the first is better than the worst 
> conversion for the second:
>
> /usr/include/QtCore/qstring.h:129: note: candidate 1: QString 
> QString::arg(double, int, char, int, const QChar&) const
>
> /usr/include/QtCore/qstring.h:625: note: candidate 2: QString 
> QString::arg(int, int, int, const QChar&) const
>
> The line it is bitching about is:
>
> tmpString.append(QString("%1").arg((int)i, 2, 10, '0') + "|");
>
> Yes, I just realized that I can put the “|” inside the QString 
> argument but I’m trying to find out what is wrong with the line 
> itself. i is an int and is a counter in a for loop.
>
> Basically, I’m trying to take an int and pad it to 2 digits and zero 
> filled. I’ll use sprintf if I have to but I’d rather not.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   


-- 
BERAUD Alexandre
Ingénieur Développement

Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site :  www.infflux.com





More information about the Qt-interest-old mailing list