Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQt: showing a file dialog after creating a pixMap produces a segmentation fault
    primarykey
    data
    text
    <p>I am developing a GUI with PyQt, to perform visual analysis of the data collected during some experiments. The GUI asks the user to indicate the directory where the data to be analyzed is located:</p> <pre><code>class ExperimentAnalyzer(QtGui.QMainWindow): ## other stuff here def loadExperiment(self): directory = QtGui.QFileDialog.getExistingDirectory(self, "Select Directory") ## load data from directory here </code></pre> <p>The GUI provides a <strong><em>play</em></strong> functionality, by means of which the user can see how experimental data changes over time. This is implemented through a <strong>QTimer</strong>:</p> <pre><code> def playOrPause(self): ## play if self.appStatus.timer is None: self.appStatus.timer = QtCore.QTimer(self) self.appStatus.timer.connect(self.appStatus.timer, QtCore.SIGNAL("timeout()"), self.nextFrame) self.appStatus.timer.start(40) ## pause else: self.appStatus.timer.stop() self.appStatus.timer = None </code></pre> <p>If I <strong><em>play</em></strong> the temporal sequence of data, then <strong><em>pause</em></strong>, then try to change the directory to load data from a new experiment, I experience a <strong>segmentation fault</strong>. </p> <p>Using some debug prints, I found out that the application crashes when I call</p> <pre><code> QtGui.QFileDialog.getExistingDirectory(self, "Select Directory") </code></pre> <p>in the <strong><em>loadExperiment</em></strong> method.</p> <p>I'm pretty new to Qt and I think I'm not handling the timer properly.<br> I'm using PyQt 4.9, Python 2.7.3 on Ubuntu 10.04.</p> <h2><strong>Edit-1</strong>:</h2> <p>After Luke's answer, I went back to my code.<br> Here's the <strong><em>nextFrame</em></strong> method, invoked every time the timer emits the <strong><em>timeout</em></strong> signal. It updates a QGraphicsScene element contained in the GUI:</p> <pre><code>def nextFrame(self): image = Image.open("&lt;some jpg&gt;") w, h = image.size imageQt = ImageQt.ImageQt(image) pixMap = QtGui.QPixmap.fromImage(imageQt) self.scene.clear() self.scene.addPixmap(pixMap) self.view.fitInView(QtCore.QRectF(0, 0, w, h), QtCore.Qt.KeepAspectRatio) </code></pre> <p>where the self.scene and the self.view objects have been previously instantiated in the GUI constructor as</p> <pre><code>self.view = QtGui.QGraphicsView(self) self.scene = QtGui.QGraphicsScene() self.view.setScene(self.scene) </code></pre> <p>I found out that commenting this line:</p> <pre><code> # self.scene.addPixmap(pixMap) </code></pre> <p>and repeating the same operations sequence reported above, the segmentation fault does not occur anymore.</p> <h2><strong>Edit-2</strong>:</h2> <p>Running the application with gdb (with python-dbg), it turns out that the segmentation fault occurs after a call to QPainter::drawPixmap.</p> <pre><code>(gdb) bt #0 0xb6861f1d in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4 #1 0xb685d491 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4 #2 0xb693bcd3 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4 #3 0xb69390bc in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4 #4 0xb6945c77 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4 #5 0xb68bd424 in QPainter::drawPixmap(QPointF const&amp;, QPixmap const&amp;) () from /usr/lib/i386-linux-gnu/libQtGui.so.4 </code></pre> <p>Therefore, it's not a problem related to timer handling, as I believed in first instance.<br> The segmentation fault happens because I'm doing something wrong with the pixMap.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload