[PyQt] Defining a custom slot in Designer

Henrik Pauli henrik.pauli at gmail.com
Sat Jan 17 23:52:10 GMT 2009


On Saturday 17 January 2009, David Boddie wrote:
> On Sat Jan 17 17:19:44 GMT 2009, Henrik Pauli wrote:
> > I was messing around in Designer today and I wanted to add my QMainWindow
> > a new slot.  The ui file has it, but the moment I try to loadUi it, I get
> > the following:
> >
> > Traceback (most recent call last):
> >  File "./testclient.py", line 11, in <module>
> >  w = uic.loadUi("testclient.ui")
> >  File "/usr/lib/python2.6/site-packages/PyQt4/uic/__init__.py", line 106,
> > in loadUi
> >  return loader.DynamicUILoader().loadUi(uifile, baseinstance)
>
> [...]
>
> >  File
> > "/usr/lib/python2.6/site-packages/PyQt4/uic/Loader/qobjectcreator.py",
> > line 75, in getSlot
> >  return getattr(object, slotname)
> > AttributeError: executeCommand
> >
> > So how do I add this to my widget?
>
> How did you add the slot to the testclient.ui file?

right-click on MainWindow, Change Signals/Slots, add a Slot.

[...]

I'll read that URL in a little, thanks.

> I'm not aware of a mechanism that lets you add slots to .ui files loaded
> at run-time, unless you use uic.loadUiType() to create a widget class from
> which you can derive a new subclass . You would presumably be able to write
> the code for the new slots in the subclass.

Yeah, this is what I ended up doing instead -- this way though I don't see 
that connection in Designer (not as if it were a problem, per se, I'm not 
much of a Designer/Glade person anyway (much to the annoyance of my 
coworkers, heheh!)).

> Maybe you can give some more information about what you're trying to do.

Hard.  I'm not even sure yet what I'm doing :)  Haven't coded in Python and Qt 
in ages, but I needed something that had a CSS-capable HTML display embedded, 
so I dug into it...  As a quick idea so I have to mess as little with the GUI 
itself as possible, I'll give out "commands" with a QLineEdit and see the 
communication log in a QTextBrowser, and if there's some HTML to be 
displayed, it goes into the WebKit thing.  The command handler was the slot I 
needed, and since I randomly found the Change Signals and Slots item in the 
menu, I thought I'd give it a try :)


More information about the PyQt mailing list