still confused with QTsignal

Boudewijn Rempt boud at rempt.xs4all.nl
Sun Jan 20 09:45:57 EST 2002


root <root at localhost.localdomain> wrote:
> I'm now more confused than ever with PYSIGNALS, 
> in the following class:


> class mixer:
>     
>      def __init__(self, parent=None):
>          self.ms=mixer_sub(None,parent)
>          QObject.connect(self.ms,PYSIGNAL("rec_button_clicked"),self.print)
>          QObject.connect(self.ms,PYSIGNAL("rec_button_clicked"),self.ms.print)

>       def print(self):
>           print "Recieved signal"  

> the print function never gets called even though the print function in the 
> self.ms object does. I have tried leaving off the 'self' in the 3rd param, 
> making mixer inherit QObject and lots of variations on the syntax. As far 
> as I can see this should work but doesn't.

Well, the second connection should call a print fuction on the
mixer_sub object -- not the print function you show here. 

As for the first connection: if the mixer_sub instance self.ms emits a
PYSIGNAL "rec_button_clicked", then print should be called. If you send
me the code, I can look at it -- from this example it's not really
clear. The signal name should be exactly right, and don't forget that
the function emitting the signal should also be called.

Note that it isn't exactly nice to create functions with names like
'print' :-).

Anyway -- here's yesterdays snippet adapted to what I think you're
trying to do now:

from qt import *
import sys

class Test(QObject):

    def __init__(self):
         QObject.__init__(self)

    def send(self):
         print "about to emit"
         self.emit(PYSIGNAL("pySig"),())
         print "emit"

    def hello(self):
        print "The slot called"

class Join:

    def __init__(self):
        print "in join"
        self.t = Test()
        QObject.connect(self.t, PYSIGNAL('pySig'), self.t.hello)
        QObject.connect(self.t, PYSIGNAL('pySig'), self.hello)
        print "connected"

    def hello(self):
        print "print called"

j = Join()
j.t.send()

-- 

Boudewijn Rempt  | http://www.valdyas.org 



More information about the Python-list mailing list