[Qt-interest] URL encoding only non-printing characters

Bob Hood bhood2 at comcast.net
Wed Apr 7 21:01:04 CEST 2010


On 4/7/2010 12:12 PM, Thiago Macieira wrote:
> Em Quarta-feira 07 Abril 2010, às 19:13:19, Bob Hood escreveu:
>> I'm displaying string values a QListView.  These string values can
>> contain anything, but in particular, non-printing characters within the
>> string cause the grief with the display; e.g., a carriage-return
>> character will cause the display of the string to end abruptly at the
>> point where it appears.
>>
>> Although these strings are not URLs, I have encoded the string using
>> QUrl::toPercentEncoding(), and that "normalizes" it so that it displays
>> completely (albiet with URL-encoded percent values) in the QListView.
>> However, I would rather encode only non-printing characters.  Others,
>> like "?" or "{", are fine for my purposes.
>>
>> Would anybody have an idea how I could specify non-printing characters
>> (line-feed, tab, etc.) in the combination of toPercentEncoding()'s
>> "include" and "exclude" settings such that only those values are percent
>> encoded?
>
> http://doc.qt.nokia.com/4.6/qurl.html#toPercentEncoding
>
> The extra parameters to toPercentEncoding indicate which characters to include 
> or exclude in the encoding. The example itself shows how to make { } not be 
> encoded.

Thanks for the reply, Thiago.

Yes, I've read the docs for toPercentEncoding().  Nothing there about
non-printing characters.  Perhaps I wasn't clear enough...

Let's say I have a string that has any kind of characters, and in that
string I only want to encode carriage returns ('\n') using
toPercentEncoding().  Would I only need to specify the carriage return
value in the "include" set?  And, if so, would I encode that as a
QChar('\n')?




More information about the Qt-interest-old mailing list