problem with QtSignals "object has no attribute 'emit'"

News123 news123 at free.fr
Sun Feb 14 07:17:40 EST 2010


Hi,

I'm having a rather small code snippet, where I create pyQT signals.
I manage creating a signal as class attribute,
but I can't create a list of signals or a signal
as object.member.


> from PyQt4.QtGui import *
> from PyQt4.QtCore import *
> 
> class MyWin(QMainWindow):
>     clssig     = pyqtSignal()
>     sigarr   = [ pyqtSignal() ]
>     def emit_them(self):
>         self.objsig = pyqtSignal()
>         self.clssig.emit()    # works
>         self.sigarr[0].emit()  # fails 
>         self.objsig.emit()  # fails
> 
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>     win = MyWin()
>     win.show()
>     win.emit_them()
>     sys.exit(app.exec_())

The two lines marked with fails will fail with following error:
> AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit'

The QT documentation states:
"New signals should only be defined in sub-classes of QObject."

I guess, that his is the reason. though I don't know enough about PyQT
to understand the magic behind.


Now my question:

How could I create an array of signals if I wished to?

I can work aroud it, but would be curious.


Thanks for shadng some light on this (for me surprising) issue.


N



More information about the Python-list mailing list