Hi all, I try to use new style for signal-slot connection [0] in my project. And have one problem that looks like bug in PyQt.
There is a dialog window with QDialogButtonBox, which has two buttons OK and Close. During the program execution I need to change behavior of Close button: pressing this button should not close the dialog but invoke another slot. Using old signal-slot connection I implement this as self.btnClose = self.buttonBox.button( QDialogButtonBox.Close ) # disconnect from rejected() slot QObject.disconnect( self.buttonBox, SIGNAL( "rejected()" ), self.reject ) # and connect to user-defined slot QObject.connect( self.btnClose, SIGNAL( "clicked()" ), self.stopProcessing ) .... # restore original state QObject.disconnect( self.btnClose, SIGNAL( "clicked()" ), self.stopProcessing ) QObject.connect( self.buttonBox, SIGNAL( "rejected()" ), self.reject ) And all works fine as I want. But when i use new style for signal-slot connection in same code self.btnClose = self.buttonBox.button( QDialogButtonBox.Close ) self.buttonBox.rejected.disconnect( self.reject ) self.btnClose.clicked.connect( self.stopProcessing ) ... self.btnClose.clicked.disconnect( self.stopProcessing ) self.buttonBox.rejected.connect( self.reject ) I get error in run-time line 147, in prepareProcess self.buttonBox.rejected.disconnect( self.reject ) TypeError: disconnect() failed between ‘rejected’ and ‘reject’ Dialog designed in QtDesigner and compiled to Python code using pyuic4. After some investigating I found that pyuic4 generates code using old-style signal-slot connections QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject) If I replace this string in generated file with new style connections self.buttonBox.accepted.connect(Dialog.accept) self.buttonBox.rejected.connect(Dialog.reject) my code again works fine. This was tested under Linux: with Python 2.6.6, Qt 4.7.0 and PyQt 4.8.1. And under Windows using - Python 2.7.3, PyQt 4.9, Qt 4.8.0 - Python 3.2.2, PyQt 4.9.1, Qt 4.8.0. I think that incompatibility between new and old style for signal-slot connections is a major bug that can cause many problems when UI created in Designer and some signals and slots should be connected and disconnected in run-time. I create simple demo for this bug, find it attached. [0] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html Thanks and sorry for my English -- Alexander Bruy
pyqt_bug.tar.bz2
Description: BZip2 compressed data
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt