[PyQt] QString, QTextEdit and Encoding problem

Yaşar Arabacı yasar11732 at gmail.com
Tue Jun 28 06:37:06 BST 2011


Thanks for the info. Do you know any decent example, tutorial, documents
etc. about qt network stack?


2011/6/28 Andreas Pakulat <apaku at gmx.de>

> On 28.06.11 06:26:24, Yaşar Arabacı wrote:
> > Hi,
> >
> > I am havin an encoding problem. If you have read my earlier post, I was
> > doing a simple chat application. Here is how it goes.
>
> You're not converting your data correctly. On the sending side you do it
> properly, decoding to utf-8 and then sending the bytes through the
> network. On the receiving side you're using Python's socket API, which
> gives you a byte-stream and then create a QString from it implicitly.
> That uses whatever your systems default-encoding is to decode the bytes
> into a string.
>
> The error is in NetConnectorWorker.run, but its not that easy to fix
> since you currently do not send the amount of bytes you cannot know on
> the receiving side wether all data has been received or not and hence
> you cannot do a correct decoding.
>
> I suggest to switch to use Qt's network stack, that'll make these things
> a bit easier since you can use QDataStream on the network socket which
> handles sending QString's just fine.
>
> If thats not possible, you'll have to add the length of the message into
> the byte-stream or always read up to the first \n and decode the content
> then and make sure the sender always sends at least 1 \n.
>
> Andreas
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110628/5251c5ca/attachment.html>


More information about the PyQt mailing list