Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Run a pyFile(QApplication) from a button of another app
Forum Updated to NodeBB v4.3 + New Features

Run a pyFile(QApplication) from a button of another app

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 1.1k Views 1 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.
  • G Offline
    G Offline
    Giakara
    wrote on last edited by
    #1

    Can I Run a pyFile(QApplication) from a button of another app ?? i tried with Qprocess and just call the file but it doesn t open the app
    is there any other way or some example

    Pl45m4P 1 Reply Last reply
    0
    • G Giakara

      Can I Run a pyFile(QApplication) from a button of another app ?? i tried with Qprocess and just call the file but it doesn t open the app
      is there any other way or some example

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Giakara said in Run a pyFile(QApplication) from a button of another app:

      i tried with Qprocess and just call the file but it doesn t open the app

      What exactly have you tried?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Giakara
        wrote on last edited by
        #3
        def start_process(self):
            self.message("Executing process.")
            self.p = QProcess()  
           self.p.start("python3", ['main.py'])
        

        i didn t find something similar to my problem I m sure i need to put more arguments
        main.py is the file with the other executable

        Pl45m4P JonBJ 2 Replies Last reply
        0
        • G Giakara
          def start_process(self):
              self.message("Executing process.")
              self.p = QProcess()  
             self.p.start("python3", ['main.py'])
          

          i didn t find something similar to my problem I m sure i need to put more arguments
          main.py is the file with the other executable

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @Giakara

          You need to give the correct path. I doubt that your program is in the same directory as your current app.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • G Offline
            G Offline
            Giakara
            wrote on last edited by
            #5

            i tried with full path too it doesnt open anything if i just import the file it runs it before i press the button maybe it needs other arguments

            eyllanescE 1 Reply Last reply
            0
            • G Giakara

              i tried with full path too it doesnt open anything if i just import the file it runs it before i press the button maybe it needs other arguments

              eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by
              #6

              @Giakara please provide a minimal and reproducible example.

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              1 Reply Last reply
              0
              • G Giakara
                def start_process(self):
                    self.message("Executing process.")
                    self.p = QProcess()  
                   self.p.start("python3", ['main.py'])
                

                i didn t find something similar to my problem I m sure i need to put more arguments
                main.py is the file with the other executable

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Giakara

                self.p.start("python3", ['/full/path/to/main.py'])
                

                is the correct way to run a Python script as a subprocess under Linux, assuming python3 is on your path (/usr/bin/python3).

                Remember that all this does is starts the other process. It doesn't wait for it, it runs in the background. What is it that your Python script does so that you even know whether it has run, or run successfully, or not?

                Look at the documentation for QProcess. Use the methods and signals to print out the status of the subprocess, capture any error and finished signals, and sometimes you need to capture standard output/error if an error message is sent there.

                eyllanescE 1 Reply Last reply
                1
                • JonBJ JonB

                  @Giakara

                  self.p.start("python3", ['/full/path/to/main.py'])
                  

                  is the correct way to run a Python script as a subprocess under Linux, assuming python3 is on your path (/usr/bin/python3).

                  Remember that all this does is starts the other process. It doesn't wait for it, it runs in the background. What is it that your Python script does so that you even know whether it has run, or run successfully, or not?

                  Look at the documentation for QProcess. Use the methods and signals to print out the status of the subprocess, capture any error and finished signals, and sometimes you need to capture standard output/error if an error message is sent there.

                  eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on last edited by
                  #8

                  @JonB OR self.p.start(sys.executable, ['/full/path/to/main.py'])

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  JonBJ G 2 Replies Last reply
                  2
                  • eyllanescE eyllanesc

                    @JonB OR self.p.start(sys.executable, ['/full/path/to/main.py'])

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @eyllanesc
                    Yes if you're coming from a Python script, which the OP is, I just meant generically like similar from, say, a C++ program. But indeed.

                    1 Reply Last reply
                    0
                    • eyllanescE eyllanesc

                      @JonB OR self.p.start(sys.executable, ['/full/path/to/main.py'])

                      G Offline
                      G Offline
                      Giakara
                      wrote on last edited by
                      #10

                      @eyllanesc this solved my my problem thank you very much!

                      JonBJ 1 Reply Last reply
                      0
                      • G Giakara

                        @eyllanesc this solved my my problem thank you very much!

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @Giakara
                        Out of interest, what does your print(sys.executable) output?

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Giakara
                          wrote on last edited by
                          #12

                          it opens the window that i create on the main.py which is not exactly qt widget it is a wrapinstance of qWidget and i don t know exactly who it works so i do this

                          JonBJ 1 Reply Last reply
                          0
                          • G Giakara

                            it opens the window that i create on the main.py which is not exactly qt widget it is a wrapinstance of qWidget and i don t know exactly who it works so i do this

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @Giakara
                            Thanks, but that wasn't at all my question. I am interested in knowing what the value of your sys.executable Python variable is, since you said self.p.start(sys.executable, ['/full/path/to/main.py']) is required to work for you rather than using "python3", that's all.

                            G 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @Giakara
                              Thanks, but that wasn't at all my question. I am interested in knowing what the value of your sys.executable Python variable is, since you said self.p.start(sys.executable, ['/full/path/to/main.py']) is required to work for you rather than using "python3", that's all.

                              G Offline
                              G Offline
                              Giakara
                              wrote on last edited by
                              #14

                              @JonB venv\Scripts\python.exe full path to python.exe

                              JonBJ 1 Reply Last reply
                              0
                              • G Giakara

                                @JonB venv\Scripts\python.exe full path to python.exe

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #15

                                @Giakara
                                Wow! So you are on Windows and were trying to run python3 as the executable! OK :)

                                1 Reply Last reply
                                1

                                • Login

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