[PyQt] RegExp and QString
Phil Thompson
phil at riverbankcomputing.com
Thu Feb 7 19:03:06 GMT 2008
On Monday 11 February 2008, Tiago Maluta wrote:
> Hi,
>
> Following Assistant (for C++) documentation about QString split method I
> saw:
>
> str = "Now: this sentence fragment.";
I assume that str is declared as a QString.
> list = str.split(QRegExp("\\b"));
> // list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ]
>
> Now, I with python I tried, a simple example:
>
>
> line = p.readline()
So line is a Python string, not a QString.
> sline = line.split(QtCore.QRegExp("[A-Z]+"))
>
> With this code I got: TypeError: PyQt expected a character buffer object.
Because a Python string knows nothing about QRegExp.
> I don't know how to fix it, if I try a delimiter just line.slipt(',') it
> works.
>
> Some ideas?
Convert the result of readline() to a QString...
line = QtCore.QString(p.readline())
Phil
More information about the PyQt
mailing list