[PyQt] Problem with UTF-8 files and QScintilla

piotr maliński riklaunim at gmail.com
Mon Dec 1 11:18:46 GMT 2008


2008/12/1 Phil Thompson <phil at riverbankcomputing.com>

> On Mon, 1 Dec 2008 11:23:38 +0100, "piotr maliński" <riklaunim at gmail.com>
> wrote:
> > I'm trying to use QScintilla with a file opened with QFile (and not
> Python
> > functions). With files that contain ascii only characters it works, but
> for
> > utf-8 files with non-ascii character it doesn't - the code snippet:
> > ############################
> > self.ui.editor.setUtf8(True)
> > ...
> > text =QtCore.QFile(url)
> > text.open(QtCore.QIODevice.ReadWrite | QtCore.QIODevice.Text)
>
> Have you tried it without the Text flag?
>


Removing it doesn't help



>
> > txt = QtCore.QString(text.readAll())
> > self.ui.editor.setText(txt)
> > text.close()
> > ############################
> >
> > If I use:
> > self.ui.editor.setText(txt.toUtf8())
> > QSci will thow exception (TypeError: argument 1 of
> QsciScintilla.setText()
> > has an invalid type) as it wants QString and not QByteArray :) Is there a
> > file encoding safe way to open a text file and pass it to QScintilla
> > widget?
> > I was using codecs and normal open with try/except - try another way/
> > solution but it was bit uggly, and had problems with some files
> encodings.
>
> You could also try QsciScintilla.read().
>
> Note, QScintilla has its own mailing list.
>
> Phil
>

Didn't seen that one ;)

I'll stick to codecs for now. Next will be detecting file encoding and
encode the text accordingly so it would display correctly :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081201/2d8ec868/attachment.html


More information about the PyQt mailing list