On Tue, Nov 29, 2011 at 7:23 PM, Tim Doty <[email protected]> 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
> [email protected]
> http://lists.pyside.org/listinfo/pyside
>
>
Hi Tim,
I tested your code with Python 3 and apiextractor, generatorrunner,
shiboken and pyside all built from
the mainline. so I was unable to reproduce this bug, which means I got a
non-empty file. As you know,
Python strings are all unicode ones (in Python 3). The minor changes I've
made to your code was to
remove the 'u' character in front of the strings[1] and changed all print()
calls to work on Python 3
properly.
Paulo
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside