[PySide] PySide calls wrong emit() inside class

Nathan Smith nathanjsmith at gmail.com
Tue Jul 23 18:31:28 CEST 2013


Hi Robert,

You've created your signal at the class level, so it is shared by all
instances of Foo. What you want is the signal at the object level, so each
instance holds its own signal. Do so by creating the signal in the __init__
method.

def __init__(self):
   QObject.__init__(self)
   self.sig = QtCore.signal(str)

Nathan
On Jul 23, 2013 11:09 AM, "Robert Schilling" <Fun_Extra_300 at gmx.net> wrote:

> Hi @ all,
>
> Consider following example:
>
> from PySide import QtCore
> from PySide.QtCore import QObject
>
> class Foo(QObject):
>
>     sig = QtCore.Signal(str)
>
>     def __init__(self):
>         QObject.__init__(self)
>
>     def emit(self):
>         self.sig.emit("1")
>
> x = Foo()
> x.emit()
>
> This example doesn't work. When calling self.sig.emit("1") actually
> Foo.emit() is invoked.
> Testing this example works with PyQt (that's what I'm migrating from).
>
> Am I doing something wrong? How can I avoid this?
>
> Regards Robert
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130723/a6290942/attachment.html>


More information about the PySide mailing list