Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QProcess use on Windows
Forum Updated to NodeBB v4.3 + New Features

QProcess use on Windows

Scheduled Pinned Locked Moved Solved Qt for Python
pyside2qt for python
9 Posts 2 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeadParrot
    wrote on last edited by
    #1

    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. startDetached doesn't work either.

    In C++ it looks like you now need to call setCreateProcessArgumentsModifier but I don't see any documentation on using this under Python.

    Any help would be greatly appreciated!

    Thanks,
    Stuart

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DeadParrot
        wrote on last edited by
        #3

        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.

        The start call isn't generating an exception and trapping the QProcess signals I get the finished signal firing with an exitCode of 1 and an exitStatus of PySide2.QtCore.QProcess.ExitStatus.NormalExit. If the start runs "dir" it works and I get an exitCode of 0 but if it runs "explorer" it also works but I get an exitCode of 1, so I'm not sure if the exitCode is significant.

        If start runs 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?

        Thanks!

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          @DeadParrot said in QProcess use on Windows:

          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++?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DeadParrot
            wrote on last edited by
            #5

            I don't see any documentation for calling setCreateProcessArgumentsModifier in PySide2 so I assume it isn't supported. But maybe someone knows more about this?

            Kent-DorfmanK 1 Reply Last reply
            0
            • D DeadParrot

              I don't see any documentation for calling setCreateProcessArgumentsModifier in PySide2 so I assume it isn't supported. But maybe someone knows more about this?

              Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6

              @DeadParrot well just try it, using the c++ docs as a model.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DeadParrot
                wrote on last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DeadParrot
                  wrote on last edited by
                  #8

                  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 setProcessEnvironment on our QProcess before the start call gets everything working.

                  Not sure if this is a PySide2 bug or not. The QProcess.execute documentation says:
                  "The environment and working directory are inherited from the calling process."
                  but it doesn't say this explicitly for start.

                  1 Reply Last reply
                  1
                  • Kent-DorfmanK Offline
                    Kent-DorfmanK Offline
                    Kent-Dorfman
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved