[Fwd: Re: [PyKDE] Typecasting]

Mark Kimsal chugadie.geo at yahoo.com
Tue Nov 14 23:09:01 GMT 2000


-------- Original Message --------
Subject: Re: [Fwd: [PyKDE] Typecasting]
Date: Mon, 13 Nov 2000 10:38:06 -0500
From: mark kimsal <chugadie.geo at yahoo.com>
Reply-To: mark at tapinternet.com
To: pyqt <pykde at mats.gmd.de>
References: <3A0F54B5.16ABAEEE at kimsal.com>

> 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