So... I take it QTextStream no longer supports Unicode in PySide 1.0.8? If this 
is the case perhaps the docs should be updated to reflect that. If not, perhaps 
the docs could be updated to reflect what now needs to be done to write Unicode 
strings. 



On Nov 29, 2011, at 16:23, Tim Doty <thoro...@mac.com> wrote:

> I finally have narrowed down an issue encountered with PySide 1.0.8 (yeah, I 
> just saw the 1.0.9 announcement, but didn't see anything that looked like 
> this). In short, a QTextEdit() based text editor I wrote stomps on files 
> whenever it saves (writes an empty string). It worked fine in previous 
> versions of PySide.
> 
> What appears to be happening is that .toPlainText() returns a unicode object 
> and for QTextStream's overloaded << operator a unicode string results in an 
> empty file.
> 
> So... how is QTextStream supposed to be used for writing unicode? (if a call 
> to .setCodec() using 'UTF-8' is put in before the string output the same 
> behavior continues so, no, that isn't it)
> 
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> from PySide.QtCore import *
> 
> myFile = '/tmp/test.txt'
> strings = ['Hello World\n', u'Goodbye, Cruel World\n']
> 
> for string in strings:
>     print 'saving %s' % string
>     fh = QFile('/tmp/test.txt')
>     if not fh.open(QIODevice.WriteOnly):
>         raise IOError, fh.errorString()
>     stream = QTextStream(fh)
>     stream << string
> 
>     fh = QFile(myFile)
>     if not fh.open(QIODevice.ReadOnly):
>         raise IOError, fh.errorString()
>     stream = QTextStream(fh)
>     while not stream.atEnd():
>         print stream.readLine()
> 
> _______________________________________________
> PySide mailing list
> PySide@lists.pyside.org
> http://lists.pyside.org/listinfo/pyside
_______________________________________________
PySide mailing list
PySide@lists.pyside.org
http://lists.pyside.org/listinfo/pyside

Reply via email to