dasen
dasen

Reputation: 377

How to cancel QProcess by clicking in QProgressDialog's cancel button?

edit:

please scroll down for the new question. Here is the original:

I have the following code:

self.progress = QtGui.QProgressDialog("Running",  "Cancel", 0, 0)   
self.progress.show()
command = "./some_script.exe"
args =  [ "some", "args"]
process = QtCore.QProcess(self)
process.start(command, args)
self.progress.close()

When I run it, the progress dialog closes imediately after starting the QProcess. How do I keep it running until the QProcess finishes?

Thank you so much

edit:

Solved it: I had to connect the finished signal to a function that closes the progress dialog:

QtCore.QObject.connect(self.process,QtCore.SIGNAL("finished(int)"),self.processCompleted)

And then:

def processCompleted(self):
    self.progress.close()

My new question is, how do I cancel the qprocess by clicking the cancel button in the progress dialog?

Upvotes: 2

Views: 2282

Answers (1)

mdurant
mdurant

Reputation: 28683

To stop the process using the close button of the progress dialog:

self.progress.canceled.connect(self.process.terminate)

Upvotes: 2

Related Questions