[PyKDE] QStrings and Python strings

Jan Ekholm chakie at infa.abo.fi
Tue Jun 19 10:08:46 BST 2001


On Mon, 18 Jun 2001, Soeren Fietzke wrote:

>>         a=self.LineEdit1.text()
>>         b="bbs.tsinghua.edu.cn"
>>         print a==b   
>> ## the   result is 0 ,that means a is not equal to b ,how
>> #can I  make my intention into reality            
>
>Note that "a" is a reference to a QString object, not a Python string.
>The following should work as expected:
> print str(a)==b   

Yes, this is something I've been bitten by several times when manipulating
string data that originates from a Qt widget of some sorts. I usually
want to manipulate the strings as Python strings, so I usually do the
conversion immediately when "getting" the string, such as:

	QLineEdit edit
	...

	text = str (edit.text ())

Then I always know that I'm dealing with Python strings, and the normal
Python string functions and methods work as expected.

--------------------+--------------------------------------------------------
Jan 'Chakie' Ekholm |     Balrog New Media    http://www.balrog.fi/
   Linux Inside     | I'm the blue screen of death, nobody hears your screams





More information about the PyQt mailing list