Le 20/09/10 10:07, Cyril Giraudon a écrit :
 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)cy...@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_()
"""""""""""""""""""""""""""""""""""""""""
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Salut,

Change these lines:

    bye_action = QAction("Bye bye", dialog)
    bye_action.triggered.connect(say_bye)
    toolbar.addAction(bye_action)

    quit_action = QAction("Quit", dialog)
    quit_action.triggered.connect(quit)
    toolbar.addAction(quit_action)

and this one:

    sys.exit(app.exec_()) 

Cheers

--
Vincent V.V.
Oqapy
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to