Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QProcess use on Windows
In PySide and PyQt5 I start a process to kick off another Python GUI application like this:
p = QProcess() p.start( "pythonw.exe", [ arg2, arg2 ], QIODevice.ReadOnly )
In PySide2 this doesn't work (at least on Windows 10): nothing happens.
startDetacheddoesn't work either.
In C++ it looks like you now need to call
setCreateProcessArgumentsModifierbut I don't see any documentation on using this under Python.
Any help would be greatly appreciated!
Kent-Dorfman last edited by Kent-Dorfman
In lieu of setting up the environment, try explicitly setting the path to the python interpretter: pythonw.exe.
also trap the signals that p.start can cause to be emmitted, to see why it is failing.
Thanks for the suggestions.
Adding the explicit path to pythonw.exe doesn't make a difference -- the PATH already contains the pythonw.exe directory. As I said, all works fine with PySide or PyQt5.
startcall isn't generating an exception and trapping the QProcess signals I get the
finishedsignal firing with an
exitCodeof 1 and an
exitStatusof PySide2.QtCore.QProcess.ExitStatus.NormalExit. If the
startruns "dir" it works and I get an
exitCodeof 0 but if it runs "explorer" it also works but I get an
exitCodeof 1, so I'm not sure if the
startruns simply "pythonw.exe" I see a pythonw process running in Task Manager. But with my arguments it exits immediately. I checked that the same pythonw.exe command line works fine at the terminal.
Can anyone shed light on what is going on here? Does PySide2 require something extra to open another PySide2 application from a QProcess? Or is QProcess buggy?
In C++ it looks like you now need to call setCreateProcessArgumentsModifier but I don't see any documentation on using this under Python.
So what happens when you do it in python exactly like you would in c++?
I don't see any documentation for calling
setCreateProcessArgumentsModifierin PySide2 so I assume it isn't supported. But maybe someone knows more about this?
@DeadParrot well just try it, using the c++ docs as a model.
@Kent-Dorfman I agree that is the next step. Unfortunately, trying it gives:
'PySide2.QtCore.QProcess' object has no attribute 'setCreateProcessArgumentsModifier'
I'm going by an SO posting that may not be relevant to the issue I'm hitting.
OK, so the issue turned out to be something different. We are using QtPy and it needs the environment variable QT_API set to pyside2 for our Windows setup. For some reason the environment passed to QProcess isn't inheriting that variable and it was defaulting to pyside. Setting it manually to pyside2 by calling
setProcessEnvironmenton our QProcess before the
startcall gets everything working.
Not sure if this is a PySide2 bug or not. The
"The environment and working directory are inherited from the calling process."
but it doesn't say this explicitly for
This post is deleted!