[PyKDE] callback not being called
david at boddie.org.uk
Mon Jan 22 22:27:24 GMT 2007
On Monday 22 January 2007 03:43, Tony Cappellini wrote:
> Well, the QT docs are all in C++, and often there are some differences for
> I've spent a lot of time reading the pyQT docs here, but it's very terse,
> and don't show any examples.
Yes, they could do to be improved. The examples in the PyQt source
distribution are ported from the C++ ones, so the documentation can be
read alongside their source code, but I'll admit that it's not ideal.
>t-slots (this is the only python-specific help I can find. It's only one
> 3.5 Connecting Signals and
> Connections between signals and slots (and other signals) are made using
> the QtCore.QObject.connect() method. For example:
> QtCore.QObject.connect(a, QtCore.SIGNAL("QtSig()"), pyFunction)
> QtCore.QObject.connect(a, QtCore.SIGNAL("QtSig()"), pyClass.pyMethod)
> QtCore.QObject.connect(a, QtCore.SIGNAL("QtSig()"), b,
> QtCore.SLOT("QtSlot()")) QtCore.QObject.connect(a,
> QtCore.SIGNAL("PySig()"), b, QtCore.SLOT("QtSlot()"))
> QtCore.QObject.connect(a, QtCore.SIGNAL("PySig"), pyFunction)
I think this page has been around for so long, in many different versions of
PyQt, that many long-time users have just memorized it. :-/
> def updateTextBox(self):
> # this function should be called, when the button is pressed
> self.patchBrowser.setPlainText(self.tr("Callback was called"))
> > However, your updateTextBox() slot is just a normal Python method, so you
> > can just pass a reference to it:
> > self.connect(self.patchNames, QtCore.SIGNAL("activated()"),
> > self.updateTextBox)
> tried this, it still doesn't call my function
My mistake, sorry! You need the following:
self.connect(self.patchNames, QtCore.SIGNAL("activated(const QString &)"),
The signal is the one shown here:
Does this help at all?
> > For slots defined by the C++ base class, you can use SLOT() to specify
> > them in the connect() call; for example, the following connection would
> > cause the dialog to be hidden when a patchNames combobox entry is
> > activated:
> > self.connect(self.patchNames, QtCore.SIGNAL("activated()"), self,
> > QtCore.SLOT("hide()"))
> tried this to, it doens't call my function either
I made the same mistake twice, thanks to cut-and-paste. :-(
> > It's quite common that people forget to provide the full signature (with
> > C++ types, but without argument names) to the SIGNAL() and SLOT()
> > functions. It would be interesting to know whether it seems like a
> > strange convention to people who have never used Qt with C++, or whether
> > it catches everyone out at some point.
I think I proved my own point. :-)
> I haven't had enough time with pyqt4 to forget anything.:-)
> I'm just trying out pyQT4, but dabbled with version 3 a few years ago.
> A lot has changed, but the signals and slots have basically stayed the
> same, from what I can see.
> The problem is trying to find python examples instead of C++ is the
> shortcoming. The python tutorial examples of the shooter game do a lot of
> the same thing, and dont use many widgets.
Do you miss Python-specific documentation or just example code to look at?
There's not a great deal that can be done right now when it comes to the
code shown in the API and example documentation, but the C++ examples
themselves can be ported to Python, and maybe they could be documented on
the PyQt Wiki. See this page for a list of those we ported for Qt 4.0 and
In the future, it would be good to actually document them on the Wiki as
well as just list the ones we manage to port.
More information about the PyQt