[PyQt] Working with os.popen and qprogressdialog

Ulf Röttger mail at ulfroettger.de
Wed Mar 12 19:11:20 GMT 2008


Am Montag 10 März 2008 20:09:27 schrieb Andreas Pakulat:
> On 10.03.08 08:45:43, Jeremiah Summers wrote:
> > Thank you but, I'm still at a loss. I tried what the Wiki said and a
> > few other pages, I've tried to understand what you said.. But as I
>
> I'm not sure how much of the wiki is usable for a beginner, as quite
> some stuff there will probably still be for PyQt3.
>
> > said I'm pretty new at this and I learn from example. I also studied
> > the class page some more, but in my reading I found that the class
> > page is out of date for Qt4. I guess QProcess has dropped addAtribute.
>
> Note sure what you were looking at but the pages you should look at are:
>
> http://www.riverbankcomputing.com/Docs/PyQt4/html/qprocess.html
> http://doc.trolltech.com/4.3/qprocess.html
>
> > some please just post a short working script that calls a bash command
> > through qprocess while displaying a progress bar for the short time
> > the script runs. I need a working example to learn from sorry to be
> > difficult. Thanks
>
> The problem is that this is not a short script. Untested and not sure
> about all the API:
>
> class MyFoo(QObject):
>   def startProc:
>     self.progress = QProgressDialog()
>     self.progress.setLabelText("Executing...")
>     self.progress.show()
>     self.proc = QProcess()
>     connect(self.proc, SIGNAL("finished(int, QProcess::ExitStatus)"),
> self.procFinished) self.start("/usr/bin/sh -c 'ls -l /usr/share/doc '")
>   def procFinished(self):
>     self.progress.hide()
>
> This should execute an ls -l /usr/share/home and show a progressbar
> while that is done.  However you'll probably need to play around a bit
> with escaping rules when you want to use pipes in the command.
>
> Andreas

Hello, I recently had to work around a similar problem, I use a not very 
elegant trick, but so far it works, maybe it helps a bit, though it is not 
what you want finally with QProcess.

stdin, stdout = os.popen2('command') 
# or use stdout = os.popen('command', 'r')
#  stdout = output of process called with 'command' - it's as if piped to the 
standard output.
for line in stdout: # for stdout is a filelike object
	print line  # at least do something with / for each line, 

this prevents following code to be processed before the command above has 
finished ;)

Ulf



More information about the PyQt mailing list