[PyKDE] signals and slots

Boudewijn Rempt boud at rempt.xs4all.nl
Sat Oct 30 17:24:29 BST 1999


I keep having problems with signals and slots, especially when there
are parameters involved... Is there someone who could tell me how to
connect a Python function to the following signals (from KHTMLView):


void setTitle ( const char *_title )  
void URLSelected ( KHTMLView *_view, const char *_url, int _button, const char *_target )  
void onURL ( KHTMLView *_view, const char *_url )  
void textSelected ( KHTMLView *_view, bool _selected )  
void popupMenu ( KHTMLView *_view, const char *_url, const QPoint &_point )  

I've tried it as follows:

self.connect(self.ilViewer, SIGNAL("setTitle (char)"), self.setTitle)
(or: elf.connect(self.ilViewer, SIGNAL("setTitle( const char *_title )"), self.setTitle))
self.connect(self.ilViewer, SIGNAL("URLSelected (KHTMLView, char, int, char)"), self.slotviewer)
self.connect(self.ilViewer, SIGNAL("onURL (KHTMLView, char)"), self.slotviewer)
self.connect(self.ilViewer, SIGNAL("textSelected (KHTMLView, bool)"), self.slotviewer)
self.connect(self.ilViewer, SIGNAL("popupMenu (KHTMLView, char, QPoint)"), self.slotviewer)

To a function 

  def setTitle(self, _title):
    print _title

  def slotviewer(self, *args):
    print args

And also with function matching number of explicit arguments, but I
keep getting

Traceback (innermost last):
  File "./kurail.py", line 290, in ?
    main()
  File "./kurail.py", line 278, in main
    toplevel=kuraWin( app=app, parent=kapp)
  File "./kurail.py", line 200, in __init__
    self.view=KuraPanels(parent=self, app=self.app)
  File "./kurail.py", line 107, in __init__
    self.connect(self.ilViewer, SIGNAL("setTitle (char)"), self.setTitle)
RuntimeError: Signal has wrong argument types for slot

I know it's probably something quite simple, but I don't get
it...

Boudewijn Rempt  | http://www.xs4all.nl/~bsarempt





More information about the PyQt mailing list