I'm using Python 2.7.5 on Ubuntu 13.10 and the PyQt4 version is 4.10.2. I'm new to PyQt and the following code demonstrates how I get the segmentation fault. after starting the python interpreter:
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtGui
>>> obj=QtGui.QGraphicsSimpleTextItem()
>>> obj.setText('sometext')
Segmentation fault (core dumped)
or initialize directly with string:
>>> from PyQt4 import QtGui
>>> obj2=QtGui.QGraphicsSimpleTextItem('some text')
Segmentation fault (core dumped)
or set text with QString object:
>>> from PyQt4 import QtGui, QtCore
>>> s=QtCore.QString('sometext')
>>> obj=QtGui.QGraphicsSimpleTextItem()
>>> obj.setText(s)
Segmentation fault (core dumped)
I must have missed something very basic. Please help. Thanks.
You should always create an QApplication instance before trying to use GUI objects/widgets:
Its a good idea to add a function to your
.pythonrc.py
which does all the necessary imports and setup for a pyqt interactive session - saves a lot of tedious re-typing!