[PyKDE] Typecasting

Phil Thompson phil at river-bank.demon.co.uk
Sat Nov 11 11:55:39 GMT 2000


mark kimsal wrote:
> 
> Okay, i've been stuck all day on this problem.
> 
> I have a class that subclasses QListViewItem, FTPDirItem.  I populate a
> QListView with a few instances of FTPDirItem.  When I connect the signal
> from the containing QListView it requires a pointer to an object of type
> QListViewItem.  When I try to access object variables inside my SLOT
> function I get AttributeErrors.  type(myobj) reveals that the program
> thinks the object is a QListViewItem at that point.  I can access
> user-defined object methods of FTPDirItem, but whenever I try to access
> variables I created in the subclasses' __init__() method I get an
> error.  So my question is how can I typecast this object back into an
> FTPDirItem inside my SLOT callback function?

I've just played with the dirview.py example, added the line...

mw.connect(mw,SIGNAL('clicked(QListViewItem *)'),handleClick)

before the exec_loop(). The handleClick function is...

def handleClick(itm):
	print itm, itm.f

This works as you'd expect - is it similar to what you are trying to do?

When you say "my SLOT function" are are actually using SLOT() in your
connect() statement? If so, don't.

If you still have the problem then send me some code (as short as
possible) that demonstrates it.

Phil




More information about the PyQt mailing list