[PySide] segfault related to NavigationToolbar when using PySide

TP paratribulations at free.fr
Sat Jul 7 11:34:55 CEST 2012


Hi everybody,

I have just posted a question on the Matplotlib mailing list:

http://sourceforge.net/mailarchive/forum.php?thread_name=4FF7A4D3.7060008%40hawaii.edu&forum_name=matplotlib-
users

I obtain a segfault when using PySide, but not PyQt4. The answer obtained on 
the Matplotlib mailing list seems to point to a possible bug in PySide.

For convenience, I have copied the Python script below at the end of this 
post.

To test with PyQt4, use:
$ python example.py

To test with PySide:
$ python example.py pyside

With PySide, a segmentation fault appears as soon as the mouse cursor is 
hovering the plot area. Without the NavigationToolbar (try to comment the 
corresponding lines), the problem does not appear. It may be related to the 
display of mouse coordinates in the NavigationToolbar, because when the mouse 
is hovering the NavigationToolbar, no segfault appears.

These are the versions of Qt, PySide, and Matplotlib on my machine:
>>> from PySide import QtCore
>>> QtCore.qVersion()
'4.8.1'
>>> from PySide import __version__
>>> __version__
'1.1.0'
>>> import matplotlib
>>> matplotlib.__version__
'1.1.1rc'

Is this a bug in PySide? If yes, does any workaround exist?

Thanks in advance,

TP

###########     example.py     ############
#!/usr/bin/env python

import sys

if len(sys.argv) >= 2 and sys.argv[1] == "pyside":
    from os import environ
    environ['QT_API'] = 'pyside'

    from PySide.QtCore import *
    from PySide.QtGui import *
else:
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *


from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg

class MplCanvasXY( FigureCanvas ):

    def __init__( self, title = None, xlabel = None, ylabel = None, 
parent=None ):

        self.fig = Figure()
        self.axes = self.fig.add_subplot(111)
        self.axes.grid(True)

        FigureCanvas.__init__( self, self.fig )
        self.setParent( parent )


app = QApplication( sys.argv )
d = QDialog()

vb = QVBoxLayout()
canvas = MplCanvasXY()

vb.addWidget( canvas )
navigationToolbar = NavigationToolbar2QTAgg(
        parent = canvas
        , canvas = canvas )
vb.addWidget( navigationToolbar )
d.setLayout( vb )

d.show()
sys.exit( app.exec_() )
##############################



More information about the PySide mailing list