[PyKDE] problem with custom signals

Phil Thompson phil at riverbankcomputing.co.uk
Mon Apr 17 09:54:14 BST 2006


On Monday 17 April 2006 3:32 am, Eron Lloyd wrote:
> On Wednesday 08 March 2006 4:35 am, Phil Thompson wrote:
> > On Wednesday 08 March 2006 8:08 am, Emanuele Santos wrote:
> > > Hi, Phil
> > >
> > > I'm using the latest version of PyQt4 (20060306) and when I try
> > > something like:
> > >
> > > self.emit(QtCore.SIGNAL("mySignal(PyObject *)", myObject)
> > >
> > > I get a type error, but if I use the short-circuited version
> > >
> > > self.emit(QtCore.SIGNAL("mySignal"), myObject)
> > >
> > > it works fine.
> > >
> > > In your e-mail (couple weeks ago) I thought both ways were supposed to
> > > work, am I correct?
> >
> > Yes, it's a bug. Will be fixed in tonight's SIP snapshot.
>
> Hi all,
>
> I'm trying to port code to PyQt4, and am having trouble implementing the
> new signal/slot convention. I did my best to try and follow the previous
> list discussions, but I still can't seem to get it to work. I wrote a test
> script that provides the kind of behavior I'm needing, basically custom
> python signals (and type arguments) passed to Qt built-in slots. I'm using
> SIP 4.4.1, yesterday's PyQt4 snapshot, and Qt 4.1.2. Thanks for any
> pointers!
>
>
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> a = QApplication([])
>
> w = QMainWindow()
> m = QWidget()
> w.setCentralWidget(m)
> l = QGridLayout(m)
> t = QTreeWidget(m)  # The "view" to be toggled
> t.setHeaderLabels(["One", "Two"])
> b1 = QPushButton("Enable", m)
> b2 = QPushButton("Disable", m)
>
> l.addWidget(t, 0, 0, 1, 2)
> l.addWidget(b1, 1, 0)
> l.addWidget(b2, 1, 1)
>
> def enable():
>     print "Enabling view..."
>     m.emit(SIGNAL("enableView"), True)  # pass to t.setEnabled(True)
>
> def disable():
>     print "Disabling view..."
>     m.emit(SIGNAL("disableView"), True)  # pass to t.setDisabled(True)
>
> m.connect(b1, SIGNAL("clicked()"), enable)
> m.connect(b2, SIGNAL("clicked()"), disable)
> m.connect(m, SIGNAL("enableView"), t, SLOT("setEnabled(bool)"))
> m.connect(m, SIGNAL("disableView"), t, SLOT("setDisabled(bool)"))
>
> if __name__ == '__main__':
>     w.show()
>     a.exec_()

Short-circuit signals (ie. those without an argument list) can only be 
connected to Python slots so you need to use...

    SIGNAL("enableView(bool)")

Phil




More information about the PyQt mailing list