[PyQt] Bye bye segmentation fault

Cyril Giraudon cyril.giraudon at free.fr
Mon Sep 20 09:07:30 BST 2010


  Hello,

I am a PyQt newbye and I wanted to do some tests with QToolBar in a 
QDialog (Seems multiple QMainWindow use is not recommanded in a 
QApplication), so I started coding a simple example (reported below).

The code seems correct but it terminates with a segmentation fault when 
the QUIT button is pressed :

"""""""""""""""""""""""""""""""""""""
(sandbox)cyril at CGN-L: pyqt$ python example.py
Qt version :  4.6.2
PyQt version :  4.7.2
Erreur de segmentation
"""""""""""""""""""""""""""""""""""""

I don't understand what happens.
Is there any explanation ?

Thanks a lot,

Cyril.


"""""""""""""""""""""""""""""""""
example.py source code
"""""""""""""""""""""""""""""""""
# -*- coding: utf8 -*-

import sys

from PyQt4.QtCore import SIGNAL, SLOT, QT_VERSION_STR, PYQT_VERSION_STR
from PyQt4.QtGui import (QApplication, QDialog, QVBoxLayout,
                          QToolBar, QAction, QLabel)

if __name__=='__main__':
     print "Qt version : ", QT_VERSION_STR
     print "PyQt version : ", PYQT_VERSION_STR

     app = QApplication(sys.argv)

     dialog = QDialog()
     dialog.setWindowTitle(u"Bye bye")

     layout = QVBoxLayout(dialog)

     toolbar = QToolBar()

     label = QLabel("Hello World!")
     def say_bye():
         label.setText("Bye Bye")
     bye_action = QAction("Bye bye", dialog, triggered=say_bye)
     toolbar.addAction(bye_action)

     quit_action = QAction("Quit", dialog)
     dialog.connect(quit_action, SIGNAL("triggered()"),
                    app, SLOT("quit()"));
     toolbar.addAction(quit_action)

     layout.addWidget(toolbar)
     layout.addWidget(label)

     dialog.show()
     app.exec_()
"""""""""""""""""""""""""""""""""""""""""


More information about the PyQt mailing list