[PyQt] Working with os.popen and qprogressdialog
Jeremiah Summers
jmiahman at gmail.com
Mon Mar 10 15:45:43 GMT 2008
On Mon, Mar 10, 2008 at 1:26 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> On 09.03.08 16:21:05, JMiahMan wrote:
> >
> >
> > Andreas Pakulat-2 wrote:
> > >
> > > Thats because while you run your process the event loop is not run and
> > > thus no painting updates are being done. I suggest to take a look at
> > > QProcess as that one sends the output in an asynchronous way and thus
> > > allows the event loop to update the paintings.
> >
>
> > I apologize I have no clue what you're saying It sounds kinda like a RTFM
> > response. I've taken a look at the Qprocess class (and the QT Class page in
> > general) but being very new at this and programming in general I understand
> > just about as much as what you said above.
>
> And in fact I was partly wrong :) os.popen doesn't actually block until
> the command is finished, but also returns immediately. And thats exactly
> your problem, the code flow you have is:
>
> show dialog
> start a child process (only starts, doesn't wait for it to finish)
> hide dialog
>
> As you can see in fact this is almost the same as doing just
>
> show dialog
> hide dialog
>
> because forking a child process is normally really fast.
>
> So what you probably really want is to find out when your child process
> is done doing what it wants to do. I'm not sure how to do that with
> standard python process management.
>
> However you can do this easily with QProcess. Check the api docs there
> are samples how to run any command you want via QProcess. Looking at
> your command string you probably need to prepends a /usr/bin/sh -c "..."
> as you're executing shell functions (such as sleep) and QProcess doesn't
> use a shell when executing the commands.
>
> QProcess then has signals which you can connect to your own slots which
> notify you when the process you started has exited. So the flow would
> then become
>
> show dialog
> start process via qprocess
> <process runs and also the Qt event loop, which draws the dialog>
> QProcess signals that the process exited
> hide dialog (in the slot connected to the signal)
>
> Andreas
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
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.
Which has now confused me even more do I then just use start?. Can
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
More information about the PyQt
mailing list