[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Help with "stringio" ops on QTextStream in Qt5
From:       David Cortesi <davecortesi () gmail ! com>
Date:       2014-02-15 18:18:33
Message-ID: CALyzANve0jB5UpkV=n=aA_a673wkAyUX+nSq2P_qmKdR11+D3Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I asked about basing an in-memory QTextStream on a QString
when QStrings are not available, and Colin replied,

Would using QByteArray in place of QString be acceptable?
>
> It seems to accept and return Python strings rather than insist on
> Python bytes and seems to cope with multi-byte characters.  However,
> since byte offset isn't equal to character offset in the case of
> multibyte characters I suppose seeking to arbitrary character positions
> would be tricky.
>

Thanks for the reply. You are correct, using QByteArray works just fine
for this. I pushed a bunch of multi-byte chars into it and got them
all back on read, Python string in, Python string out.

Your point about seeking to a character position is cogent, but
fortunately I only care about using seek(0) to "rewind" the stream.

It is possible to set the encoding of a QTextStream, e.g.

>   stream.setCodec(QTextCodec.codecForName('UTF-8'))

but this doesn't seem to be necessary, at least in Mac OS.
However, maybe it should be done to ensure consistency.
The default codec is supposedly QTextCodec.codecForLocale()
I'm not sure whether this might cause a change of
behavior when moving the app to different platforms.

Thanks again for the help!

[Attachment #5 (text/html)]

<div dir="ltr">I asked about basing an in-memory QTextStream on a QString<br>when \
QStrings are not available, and Colin replied,<br><br><div><div \
class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" \
style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">


Would using QByteArray in place of QString be acceptable?<br>
<br>
It seems to accept and return Python strings rather than insist on<br>
Python bytes and seems to cope with multi-byte characters.  However,<br>
since byte offset isn&#39;t equal to character offset in the case of<br>
multibyte characters I suppose seeking to arbitrary character positions<br>
would be tricky.<br></blockquote><div><br></div><div>Thanks for the reply. You are \
correct, using QByteArray works just fine<br>for this. I pushed a bunch of multi-byte \
chars into it and got them<br>all back on read, Python string in, Python string \
out.<br>

<br>Your point about seeking to a character position is cogent, but<br>fortunately I \
only care about using seek(0) to &quot;rewind&quot; the stream.<br><br>It is possible \
to set the encoding of a QTextStream, e.g.<br><br>

&gt;   stream.setCodec(QTextCodec.codecForName(&#39;UTF-8&#39;))<br><br>but this \
doesn&#39;t seem to be necessary, at least in Mac OS.<br>However, maybe it should be \
done to ensure consistency.<br>The default codec is supposedly \
QTextCodec.codecForLocale()<br>

</div><div>I&#39;m not sure whether this might cause a change \
of<br></div><div>behavior when moving the app to different \
platforms.<br></div><div><br></div><div>Thanks again for the \
help!<br></div><div><br></div></div></div>

</div></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic