[Fwd: [PyKDE] Typecasting]
mark kimsal
chugadie.geo at yahoo.com
Mon Nov 13 16:41:20 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?
>
Yes it behaves exactly as I'd expect:
<qt.QListViewItem instance at 0079CD4C>
Traceback (most recent call last):
File "qt/pyqt22/examples/dirview.py", line 66, in handleClick
print itm, itm.f
AttributeError: f
Sub classes of QListViewItem are not passed from QListView SIGNALS akaict.
>
> When you say "my SLOT function" are are actually using SLOT() in your
> connect() statement? If so, don't.
>
No, in my project and the modified dirview I am not using the SLOT()
construct, I'm just typing the name of a python function.
> 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