Help on PyQt4 QProcess

Phil Thompson phil at riverbankcomputing.com
Fri Aug 19 13:56:30 EDT 2011


On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes
<fuentesej at gmail.com> wrote:
> Dear friends,
> 
> I need execute an external program from a gui using PyQt4, to avoid
> that hang the main thread, i must connect the signal "finished(int)"
> of a QProcess to work properly.
> 
> for example, why this program don't work?
> 
>    from PyQt4.QtCore import QProcess
>    pro = QProcess() # create QProcess object
>    pro.connect(pro, SIGNAL('started()'), lambda
> x="started":print(x))        # connect
>    pro.connect(pro, SIGNAL("finished(int)"), lambda
> x="finished":print(x))
>    pro.start('python',['hello.py'])        # star hello.py program
> (contain print("hello world!"))
>    timeout = -1
>    pro.waitForFinished(timeout)
>    print(pro.readAllStandardOutput().data())
> 
> output:
> 
>    started
>    0
>    b'hello world!\n'
> 
> see that not emit the signal finished(int)

Yes it is, and your lambda slot is printing "0" which is the return code
of the process.

Phil



More information about the Python-list mailing list