Scope <or> PyQt question
dittonamed
dittonamed at gmail.com
Thu Jul 26 12:00:44 EDT 2007
On Jul 26, 10:15 pm, Stargaming <stargam... at gmail.com> wrote:
> On Thu, 26 Jul 2007 06:41:44 -0700, dittonamed wrote:
> > Code pasted below ----->
>
> > Can anyone out there suggest a way to access the object "p" thats
> > started in playAudio() from inside the stopAudio()? I need the object
> > reference to use QProcess.kill() on it. The code sample is below. Thanks
> > to anyone who helps out =)
>
> > More comments in the code below ------>
>
> > from qt import *
>
> > class Form2(QMainWindow):
> > def __init__(self,parent = None,name = None,fl = 0):
> > QMainWindow.__init__(self,parent,name,fl) self.statusBar()
>
> > def playAudio(self):
> > p = QProcess(self, 'player')
> > playcmd = '/usr/bin/play'
> > filename = 'song.ogg'
> > p.addArgument(playcmd)
> > p.addArgument(filename)
> > p.start()
>
> > def stopAudio(self):
> > ''' #This is just to show that i can "see" the object, though
> > i
> > #dont know how to "access" it
> > #the output shows the QProcess object by name... # but how do
> > i reference it??
> > allobjs = list(QObject.objectTrees()) for obj in allobjs:
> > objName = QObject.name(obj)
> > if objName == 'Form2':
> > print QObject.children(obj)
> > '''
>
> > QProcess.kill(NEED THE REFERENCE HERE)
>
> Answering from a non-Qt point of view (ie. I don't know if there were
> cleaner ways using Qt stuff), you have to bind p somewhere not local to
> the function. Any attribute of `self` (that's hopefully not used by
> QMainWindow) should be fine.- Hide quoted text -
>
> - Show quoted text -
I was having trouble getting that to work and thought it because of
event driven nature of gui/qt programming. But i'll give it another go
anyway .. any examples? ;-)
Im wondering what the "right" way to do this is - the Qt way, or is
what you mentioned in fact the "right" way? Can i access the QObject
another way or am i barking up the wrong tree?
Thanks Stargaming and to anyone else who has some input!
Ben
More information about the Python-list
mailing list