[PyQt] General questions on parsing large QStrings

David Cortesi davecortesi at gmail.com
Mon May 13 06:12:00 BST 2013


Thanks to you and Mathias for the prompt replies.

 >     docstring = unicode( myEditor.toPlainText() )
> In PyQt5 toPlainText() will return a str object for Python3 and a unicode
> object for Python2.
>

And, as Mathias says, it is a copy?...
That is not IMO a good design choice. At least if toPlainText
returns a const QString reference, one can then use r/o QString
methods like count(), contains(), indexOf etc, without penalty.
Also one could provide it to a QRegExp, e.g.:

    j = qre.indexIn( myEditor.toPlainText() )
    while j >= 0 :
        # ...do something with qre.cap(0)...
        j = qre.indexIn( myEditor.toPlainText() , j )

This is more or less the patther of a syntax highlighter
as well as other possible applications -- and it
would be a catastrophe with a large doc when every
toPlainText call does a new memcopy.

In short, I urge you to leave the conversion to Python str
in the programmer's hands, e.g. via unicode() or str().

Or, find a way to support those "STL-style iterators"
that are currently omitted...?

> Also in regard to making intensive loops faster
> how well do PyQtx calls integrate with Cython or PyPy?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130512/adfdda58/attachment.html>


More information about the PyQt mailing list