[PyKDE] Converting QStrings to Python strings
Phil Thompson
phil at river-bank.demon.co.uk
Mon May 6 11:56:00 BST 2002
Janos Blazi wrote:
>
> I thought that PyQt would convert QStrings to Python strings automatically,
> but this seems not to be true:
>
> ---------------------------------------------------------------------------
> import sys
> from qt import *
>
> app=QApplication(sys.argv)
> vbox=QVBox()
>
> edit=QLineEdit(vbox)
> ok=QPushButton('Finish',vbox)
> QObject.connect(ok,SIGNAL("clicked()"),app,SLOT("quit()"))
> vbox.show()
>
> app.exec_loop()
> print int(edit.text())
> --------------------------------------------------------------------------
>
> In this code I read a string from a QLineEdit and try to convert it to an
> integer but this is not possible as the return value edit.text() is a QString.
> (I also get a segmentation fault, who knows, why?)
>
> So how can I convert the QString to a Python string?
Read the section in the documentation called "Python Strings, Qt Strings
and Unicode".
Phil
More information about the PyQt
mailing list