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. How I can run python script from QT
Forum Updated to NodeBB v4.3 + New Features

How I can run python script from QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 5 Posters 2.3k 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.
  • W Offline
    W Offline
    Wasee
    wrote on 7 Mar 2022, 12:44 last edited by
    #6

    Hi everyone;
    I need to pass two argument with script to with qt code. These argument entered from the linedit etc.
    thanks

    A 1 Reply Last reply 7 Mar 2022, 12:52
    0
    • W Wasee
      7 Mar 2022, 12:44

      Hi everyone;
      I need to pass two argument with script to with qt code. These argument entered from the linedit etc.
      thanks

      A Offline
      A Offline
      artwaw
      wrote on 7 Mar 2022, 12:52 last edited by
      #7

      @Wasee
      Do you really need it detached?
      Anyway, arguments can be bundled further down the line:

      process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));
      

      and so on.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      0
      • W Wasee
        7 Mar 2022, 12:27

        Hi everyone;
        I coded following but did not run script;

           
            QProcess process;
            process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py");
            qDebug()<<"Welcome";
        

        thanks

        J Offline
        J Offline
        JonB
        wrote on 7 Mar 2022, 12:57 last edited by
        #8

        @Wasee said in How I can run python script from QT:

        process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py");

        As I stated earlier, is /bin/python correct for your desired Python on your machine?

        Since when has Python used a -c argument to run a script? Did you try /bin/python -c /home/user/bashScripts/test.py from the command-line first? Remove that -c argument?

        If it still does not work, check for errors and any output to stdout/stderr from QProcess.

        A 1 Reply Last reply 7 Mar 2022, 12:59
        0
        • J JonB
          7 Mar 2022, 12:57

          @Wasee said in How I can run python script from QT:

          process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py");

          As I stated earlier, is /bin/python correct for your desired Python on your machine?

          Since when has Python used a -c argument to run a script? Did you try /bin/python -c /home/user/bashScripts/test.py from the command-line first? Remove that -c argument?

          If it still does not work, check for errors and any output to stdout/stderr from QProcess.

          A Offline
          A Offline
          artwaw
          wrote on 7 Mar 2022, 12:59 last edited by
          #9

          @JonB said in How I can run python script from QT:

          Since when has Python used a -c argument to run a script?

          https://docs.python.org/3/using/cmdline.html

          seems legit? I assumed the OP knows how to call an interpreter and used the parameter deliberately.

          For more information please re-read.

          Kind Regards,
          Artur

          J 1 Reply Last reply 7 Mar 2022, 13:10
          0
          • W Offline
            W Offline
            Wasee
            wrote on 7 Mar 2022, 13:08 last edited by
            #10

            @artwaw said in How I can run python script from QT:

            process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));

            Didn't run script by changing the code.

            J 1 Reply Last reply 7 Mar 2022, 13:11
            0
            • A artwaw
              7 Mar 2022, 12:59

              @JonB said in How I can run python script from QT:

              Since when has Python used a -c argument to run a script?

              https://docs.python.org/3/using/cmdline.html

              seems legit? I assumed the OP knows how to call an interpreter and used the parameter deliberately.

              J Offline
              J Offline
              JonB
              wrote on 7 Mar 2022, 13:10 last edited by
              #11

              @artwaw
              Nope, you mis-read what is there!

              python  [-c command]
              

              runs command as as python, not as a python file of script.

              As it says there, to run a script file it's

              python myscript.py
              

              I imagine the OP copied the -c directly from the example of the Bash script, which does use -c for a file:

              /bin/bash -c myscript.sh
              

              :)

              1 Reply Last reply
              2
              • W Wasee
                7 Mar 2022, 13:08

                @artwaw said in How I can run python script from QT:

                process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));

                Didn't run script by changing the code.

                J Offline
                J Offline
                JonB
                wrote on 7 Mar 2022, 13:11 last edited by JonB 3 Jul 2022, 13:12
                #12

                @Wasee said in How I can run python script from QT:

                process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));
                Didn't run script by changing the code.

                Already told you why earlier, what you should test, and what you need to have. Any particular reason to just ignore me?

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  Wasee
                  wrote on 8 Mar 2022, 04:01 last edited by
                  #13

                  @JonB Hi;
                  I run in command-line following commands: command not found
                  user@user-HP:~$ sudo /bin/python -c /home/user/bashScripts/test.py
                  [sudo] password for user:
                  sudo: /bin/python: command not found
                  user@user-HP:~$ sudo /bin/python /home/user/bashScripts/test.py
                  [sudo] password for user:
                  sudo: /bin/python: command not found
                  user@user-HP:~$

                  thanks

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    Wasee
                    wrote on 8 Mar 2022, 04:15 last edited by
                    #14

                    @JonB said in How I can run python script from QT:

                    python myscript.py

                    Its work perfect now I want to pass two arguments with my script from UI basically two different integers.

                    thanks

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      Wasee
                      wrote on 8 Mar 2022, 04:50 last edited by
                      #15

                      Hi everyone;
                      I coded following my script run successfully:

                      process.startDetached("python /home/user/bashScripts/test.py");
                      

                      But when I pass arguments then my script fails to run ; I coded following script as argument:

                      process.startDetached(({"python /home/user/bashScripts/test.py",(ui->pan->text().simplified()),(ui->tilt->text().simplified());}));
                      

                      thanks

                      J 1 Reply Last reply 8 Mar 2022, 06:15
                      0
                      • W Wasee
                        8 Mar 2022, 04:50

                        Hi everyone;
                        I coded following my script run successfully:

                        process.startDetached("python /home/user/bashScripts/test.py");
                        

                        But when I pass arguments then my script fails to run ; I coded following script as argument:

                        process.startDetached(({"python /home/user/bashScripts/test.py",(ui->pan->text().simplified()),(ui->tilt->text().simplified());}));
                        

                        thanks

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 8 Mar 2022, 06:15 last edited by
                        #16

                        @Wasee Please read QProcess documentation!
                        And also please read what @JonB gave you!

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2

                        15/16

                        8 Mar 2022, 04:50

                        • Login

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