[PyKDE] List confusion
Phil Thompson
phil at riverbankcomputing.co.uk
Wed Sep 24 09:48:01 BST 2003
On Wednesday 24 September 2003 8:02 am, Derek Fountain wrote:
> This might be a general Python newbie question. But it's confusing me in a
> PyQt context. :o)
>
> I have a slot in a class which receives a list of images. It adds that list
> to it's existing list, then sends off a signal saying the existing list has
> changed:
>
> currentImageList = []
> def slotInsertImages( self, imageList ):
> self.currentImageList.extend( imageList )
> self.emit( PYSIGNAL("signalUpdateImageList"), self.currentImageList
> )
>
> This doesn't work. I get an error saying:
>
> TypeError: Argument 2 of QObject.emit() has an invalid type
>
> Changing the "self.currentImageList" to "(self.currentImageList,)" makes it
> work.
>
> On the other end of that signal is a slot which looks like this:
>
> def slotUpdateImageList( self, imageList ):
> print "update image list"
> for file in imageList:
> print file
>
> Which also works. :o)
>
> What I don't understand is why I need to force the currentImageList into a
> tuple with one item - that item being my list of image names. What is
> received at the other end is clearly a list since I can loop over it. It
> feels like the slot should have to take the first index of its 'imageList'
> argument, but that's clearly not the case.
>
> What's going on? What does the self.emit() method actually do with it's
> second argument?
Interprets it as an argument list (so it has to be a tuple) and calls the slot
with those arguments. An example with two arguments might make it clearer...
self.emit( PYSIGNAL("signalUpdateImageList"), (self.currentImageList, flag))
def slotUpdateImageList( self, imageList, flag ):
Should emit() take a variable number of arguments rather than a single tuple?
Maybe, but it's too late to change now.
Phil
More information about the PyQt
mailing list