Qt-interest Archive, March 2002
cannot print encoded URL to console with QString
Message 1 in thread
hi all,
I have some encoded URL that I want to print to console using qDebug. but it
give me junk instead of the actual string. I believe that is because encoded
URL has '%' in it, and '%' is special to QString. so everytime qDebug try to
print '%', it mess up and print junk instead (such as hundreds of space or
some negative number)
e.g.
QString n = "some string";
QUrl::encode( n );
qDebug( n ) // this mess up because of %20 in the encoded n
how do I print it properly???
thanks
ben
Message 2 in thread
Op dinsdag 26 maart 2002 15:45, schreef u:
> hi all,
hi,
>
> I have some encoded URL that I want to print to console using qDebug. but
> it give me junk instead of the actual string. I believe that is because
> encoded URL has '%' in it, and '%' is special to QString. so everytime
> qDebug try to print '%', it mess up and print junk instead (such as
> hundreds of space or some negative number)
>
> e.g.
>
> QString n = "some string";
> QUrl::encode( n );
> qDebug( n ) // this mess up because of %20 in the encoded n
>
> how do I print it properly???
>
> thanks
> ben
AFAIK qDebug cannot print QString objects directly, using qDebug ( n.latin1()
); should work properly (note that latin1() isn't exactly i18n friendly
should this be a concern of yours)
regards,
Klaas
Message 3 in thread
Am Dienstag, 26. März 2002 15:57 schrieb Klaas Koper:
> Op dinsdag 26 maart 2002 15:45, schreef u:
> > hi all,
>
> hi,
>
> > I have some encoded URL that I want to print to console using qDebug. but
> > it give me junk instead of the actual string. I believe that is because
> > encoded URL has '%' in it, and '%' is special to QString. so everytime
> > qDebug try to print '%', it mess up and print junk instead (such as
> > hundreds of space or some negative number)
> >
> > e.g.
> >
> > QString n = "some string";
> > QUrl::encode( n );
> > qDebug( n ) // this mess up because of %20 in the encoded n
> >
> > how do I print it properly???
> >
> > thanks
> > ben
>
> AFAIK qDebug cannot print QString objects directly, using qDebug (
> n.latin1() ); should work properly (note that latin1() isn't exactly i18n
> friendly should this be a concern of yours)
>
> regards,
>
> Klaas
You can pass a QString to qDebug, but the problem is that qDebug interprets
the first parameter as a format string and so you're in trouble when your
string contains %-characters. Just do the following:
qDebug("%s", s.latin1());
Concerning the i18n-friendliness is of lesser concern in qDebug output, at
least in my opinion.
greetings,
P.J.
--
[ signature omitted ]