Young-Ho_Song | 2020-12-30 06:49:22 UTC | #1
Hi. Thank you very much for the nice tutorial about running external program in Qt. I would like to ask a question about QProcess. If the external program is in different folder of the Qt code, how should one call an external program in its own directory?
Suppose external program is in 'C:/program_folder/test.exe' (with its own input files in that directory.) and the Qt code is in 'C:/qt_source/test.py' I tried
p = QProcess()
p.setWorkingDirectory('C:/program_folder/')
p.start('test.exe')
But, it did not work. Could you help me for this problem?
Thank you.
Young-Ho_Song | 2021-01-06 13:57:07 UTC | #2
I found a solution. The problem semes to be from inconsistent use of setWorkingDirectory() and start(). After changing the code as follows, setWorkingDirectory() works.
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]p = QProcess()
p.setProgram('C:/program_folder/test.exe')
p.setWorkingDirectory("C:/program_folder")
p.start()
martin | 2021-01-06 13:56:55 UTC | #3
Thanks for posting the solution @Young-Ho_Song -- I was out of the office over Christmas so missed this til now.
I wonder if this is related to the p.start('program')
method now being deprecated?
If you look at the Qt documentation for start you'll see you now must pass in the program name and the arguments as a separate list. For no arguments, you pass an empty list. I should make this clearer in the tutorial I think.
The method with only the program name -- where you could pass the arguments in the same string -- is deprecated.
Create GUI Applications with Python & Qt5 by Martin Fitzpatrick — (PyQt5 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!