[PySide] New-style signals: no Signal.connect()?

3,186 views
Skip to first unread message

Dan Halbert

unread,
Oct 4, 2010, 4:41:44 PM10/4/10
to pys...@lists.openbossa.org
I tried to use new-style signals on the Ubuntu 0.4.1 pyside build:

from PySide.QtCore import *

sig = Signal()
def foo(): print 2
sig.connect(foo)

AttributeError: 'Signal' object has no attribute 'connect'

I'm confused. From the examples in http://www.pyside.org/docs/pyside/newsigslot.html I thought you can call connect() on Signal objects. Some previous mail on the mailing list implies this should work on this release (and some earlier ones). What am I doing wrong?

Thanks,
Dan

Dan Halbert

unread,
Oct 4, 2010, 5:16:50 PM10/4/10
to pys...@lists.openbossa.org
On Monday, October 4, 2010 4:41pm, "Dan Halbert" <hal...@halwitz.org> said:
>I tried to use new-style signals on the Ubuntu 0.4.1 pyside build:
>from PySide.QtCore import *

>sig = Signal()
>def foo(): print 2
>sig.connect(foo)

>AttributeError: 'Signal' object has no attribute 'connect'

Sorry! Never mind - my example was too simple. The Signal() has to be defined in an class that inherits from QObject, and you have to instantiate such an object:

class C(QObject):
sig = Signal()

def foo():
print 2

c = C()
# Note that: C.sig.connect(foo) does not work.
c.sig.connect(foo)

In my actual program which provoked the original email, I referred to a signal by referencing it through the class, not the instance.

_______________________________________________
PySide mailing list
PyS...@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Renato Araujo Oliveira Filho

unread,
Oct 4, 2010, 5:48:47 PM10/4/10
to Dan Halbert, pys...@lists.openbossa.org
Hi Dan,

I wrote this example base on your example, and works very well.

from PySide.QtCore import QObject, Signal

class C(QObject):
sig = Signal()

def foo():
print 2

c = C()
c.sig.connect(foo)
c.sig.emit()

OUTPUT:
# python test.py
2


Which error do you get, when you try connect the signal? Can you send
the python back trace? Which version of pyside are you using?

BR

--
Renato Araujo Oliveira Filho
Instituto Nokia de Tecnologia - INdT
Mobile: +55 (81) 8704-2144

Dan Halbert

unread,
Oct 4, 2010, 6:23:00 PM10/4/10
to pys...@lists.openbossa.org
On 10/4/2010 5:48 PM, Renato Araujo Oliveira Filho wrote:
> Hi Dan,
>
> I wrote this example base on your example, and works very well.
>
> from PySide.QtCore import QObject, Signal
>
> class C(QObject):
> sig = Signal()
>
> def foo():
> print 2
>
> c = C()
> c.sig.connect(foo)
> c.sig.emit()
>
> OUTPUT:
> # python test.py
> 2
>
>
> Which error do you get, when you try connect the signal? Can you send
> the python back trace? Which version of pyside are you using?
Sorry, I was not clear in my second email. My second example -does- work
fine, for me too. My first example, which just used a bare call to
Signal(), not in a class, and not using an instance of the class, did
not work. Then I reread the documentation page more carefully and saw I
had to make the Signal() be in a class and be used from an instance.

So I am all set - everything works now.

Thanks,
Dan

Reply all
Reply to author
Forward
0 new messages